#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(m, vector<int>(2));
  int count = 0;
  for (int i = 0; i < m; ++i) {
    cin >> a[i][1] >> a[i][0];
  }
  sort(a.begin(), a.end());
  int i = (m - 1);
  while (n && i >= 0) {
    if (n <= a[i][1]) {
      count += (n * a[i][0]);
      n = 0;
    } else {
      n -= a[i][1];
      count += (a[i][1] * a[i][0]);
      i--;
    }
  }
  cout << count;
  return 0;
}
