#include <bits/stdc++.h>
using namespace std;
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second > b.second);
}
int main() {
  int n, m, res = 0, aux;
  cin >> n >> m;
  int a[m], b[m];
  vector<pair<int, int> > v;
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
    v.push_back({a[i], b[i]});
  }
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < m && n; ++i) {
    aux = min(n, v[i].first);
    res += (aux * v[i].second);
    n = n - aux;
  }
  cout << res << endl;
  return 0;
}
