#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const long long inf = 1e9 + 77;
const int MOD = 1e8 + 7;
const double eps = 1e-7;
vector<pair<int, int> > v;
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    v.push_back({y, x});
  }
  int res = 0;
  sort(v.begin(), v.end(), greater<pair<int, int> >());
  for (int i = 0; i < m; ++i) {
    if (v[i].second < n) {
      res += (v[i].second * v[i].first);
    } else {
      res += (v[i].first * n);
      break;
    }
    n -= v[i].second;
  }
  cout << res;
  return 0;
}
