#include <bits/stdc++.h>
using namespace std;
bool compareContainer(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second)
    return (a.second > b.second);
  else
    return (a.first > b.first);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, result = 0;
  cin >> n >> m;
  vector<pair<int, int>> containers(m);
  for (int i = 0; i < m; ++i) {
    int f, s;
    cin >> f >> s;
    containers[i] = make_pair(f, s);
  }
  sort(containers.begin(), containers.end(), compareContainer);
  int i = 0;
  while (n != 0 && i < containers.size()) {
    if (containers[i].first <= n) {
      n -= containers[i].first;
      result += containers[i].second * containers[i].first;
      i++;
    } else {
      int x = containers[i].first - n;
      if (x > 0) {
        int temp = containers[i].first;
        containers[i].first -= n;
        result += containers[i].second * (temp - containers[i].first);
        n -= temp - containers[i].first;
      }
    }
  }
  cout << result << endl;
  return 0;
}
