#include <bits/stdc++.h>
using namespace std;
bool sortbysec(pair<long long, long long> &a, pair<long long, long long> &b) {
  return a.second > b.second;
}
int main() {
  long long int n, m, i, j, w, sum = 0, mn, ind, t, s3 = 0, b, c = 0, l, d, r,
                               ans, x, y, mx = -1, k;
  cin >> n >> m;
  vector<pair<long long, long long> > v;
  pair<long long, long long> z;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    z = make_pair(x, y);
    v.push_back(z);
  }
  sort(v.begin(), v.end(), sortbysec);
  for (i = 0; i < v.size(); i++) {
    if (v[i].first <= n - sum) {
      c += (v[i].first) * (v[i].second);
      sum += v[i].first;
    } else {
      c += (n - sum) * (v[i].second);
      break;
    }
  }
  cout << c;
}
