//Done by: K Ashwin
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)
#define s(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define set0(a) memset(a, 0, sizeof(a))
#define setdp(a) memset(a, -1, sizeof(a))
#define INF 2000000000
#define MOD 1000000007
vector <pair <ll, ll> > v;
int main()
{
ll n, c, x, y;
cin >> n >> c;
REP (i, 1, c) {
cin >> x >> y;
v.pb(mp(y, x));
}
sort(v.rbegin(), v.rend());
ll ans = 0;
TR (v, it) {
ans += (it->first) * min(n, it->second);
n -= min(n, it->second);
}
cout << ans << endl;
return 0;
}
Ly9Eb25lIGJ5OiBLIEFzaHdpbgoKI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBwYWlyPGludCwgaW50PiBwaWk7CgojZGVmaW5lIFJFUChpLCBhLCBiKSBcCmZvciAoaW50IGkgPSBpbnQoYSk7IGkgPD0gaW50KGIpOyBpKyspIC8vIGEgdG8gYiwgYW5kIHZhcmlhYmxlIGkgaXMgbG9jYWwhCiNkZWZpbmUgVFIoYywgaXQpIFwKZm9yIChhdXRvIGl0ID0gKGMpLmJlZ2luKCk7IGl0ICE9IChjKS5lbmQoKTsgaXQrKykKCiNkZWZpbmUgcyh4KSBzY2FuZigiJWQiLCAmeCkKI2RlZmluZSBzbCh4KSBzY2FuZigiJWxsZCIsICZ4KQojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIGZpIGZpcnN0CiNkZWZpbmUgc2Ugc2Vjb25kCiNkZWZpbmUgc2V0MChhKSBtZW1zZXQoYSwgMCwgc2l6ZW9mKGEpKQojZGVmaW5lIHNldGRwKGEpIG1lbXNldChhLCAtMSwgc2l6ZW9mKGEpKQojZGVmaW5lIElORiAyMDAwMDAwMDAwCiNkZWZpbmUgTU9EIDEwMDAwMDAwMDcKCnZlY3RvciA8cGFpciA8bGwsIGxsPiA+IHY7CgppbnQgbWFpbigpCnsKICAgIGxsIG4sIGMsIHgsIHk7CgogICAgY2luID4+IG4gPj4gYzsKCiAgICBSRVAgKGksIDEsIGMpIHsKICAgICAgICBjaW4gPj4geCA+PiB5OwoKICAgICAgICB2LnBiKG1wKHksIHgpKTsKICAgIH0KCiAgICBzb3J0KHYucmJlZ2luKCksIHYucmVuZCgpKTsKCiAgICBsbCBhbnMgPSAwOwogICAgVFIgKHYsIGl0KSB7CiAgICAgICAgYW5zICs9IChpdC0+Zmlyc3QpICogbWluKG4sIGl0LT5zZWNvbmQpOwogICAgICAgIG4gLT0gbWluKG4sIGl0LT5zZWNvbmQpOwogICAgfQoKICAgIGNvdXQgPDwgYW5zIDw8IGVuZGw7CgogICAgcmV0dXJuIDA7Cn0=
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/py_compile.py", line 117, in compile
raise py_exc
py_compile.PyCompileError: File "prog.py", line 1
//Done by: K Ashwin
^
SyntaxError: invalid syntax