#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[i].first = b, v[i].second = a;
  }
  sort(v.begin(), v.end());
  long long sum = 0;
  for (int i = m - 1; i >= 0; i--) {
    if (n > v[i].second)
      n -= v[i].second, sum += (long long)v[i].second * v[i].first;
    else {
      sum += (long long)n * v[i].first;
      break;
    }
  }
  cout << sum;
}
