#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  long long int m;
  cin >> m;
  vector<pair<long long int, long long int>> v(m);
  for (long long int i = 0, x, y; i < m; ++i) {
    cin >> x >> y;
    v[i].second = x;
    v[i].first = y;
  }
  sort(v.begin(), v.end(), greater<pair<long long int, long long int>>());
  long long int it = 0;
  long long int sum = 0;
  while (n > 0 && it < m) {
    if (v[it].second >= n) {
      sum += (n * v[it].first);
      break;
    } else {
      n -= v[it].second;
      sum += ((v[it].first) * (v[it].second));
      ++it;
    }
  }
  cout << sum << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
