#include <bits/stdc++.h>
using namespace std;
int n, m;
long long res;
pair<long long, long long> a[40];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> a[i].second >> a[i].first;
  sort(a, a + m);
  for (int i = m - 1; i >= 0 && n > 0; i--)
    res += a[i].first * min(a[i].second, (long long)n), n -= a[i].second;
  cout << res;
  return 0;
}
