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