#include <bits/stdc++.h>
using namespace std;
void go() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  go();
  long long q, a, c = 0, t = 0, b, n, m;
  vector<pair<long long, long long>> v;
  cin >> n >> m;
  while (m--) {
    cin >> a >> b;
    v.push_back({b, a});
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < v.size(); i++) {
    c = (min(n, v[i].second));
    t += (c * v[i].first);
    n -= c;
  }
  cout << t;
  return 0;
}
