#include <iostream>
using namespace std;
int main(){
int x,n;
cin >> x >> n;
long long sum = 0;
for(int i = 1; i <= n; i++)
{
int a,b;
cin >> a >> b;
long long cnt = 1;
for(int j = 1; j <= b;j ++)
{
cnt *= x;
}
sum += a * cnt;
}
cout << sum;
return 0;