#include <bits/stdc++.h>
using namespace std;
int main() {
  int m;
  uint64_t n;
  cin >> n >> m;
  pair<int, uint64_t>* p = new pair<int, uint64_t>[m];
  for (int i = 0; i < m; i++) {
    cin >> p[i].second >> p[i].first;
  }
  if (m == 1) {
    if (n > p[0].second) {
      cout << p[0].second * p[0].first;
    } else {
      cout << n * p[0].first;
    }
    return 0;
  }
  sort(p, p + m);
  uint64_t sum = 0, match = 0;
  int i = m - 1;
  while (sum < n && i >= 0) {
    if (p[i].second <= (n - sum)) {
      match += p[i].second * p[i].first;
      sum += p[i].second;
      i--;
    } else {
      match += (n - sum) * p[i].first;
      break;
    }
  }
  cout << match;
  return 0;
}
