#include <bits/stdc++.h>
using namespace std;
int main() {
  using ll = long long;
  int n, m;
  cin >> n >> m;
  long long ans = 0;
  vector<pair<ll, ll>> v(m);
  for (auto &a : v) {
    cin >> a.second >> a.first;
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < m and n; ++i) {
    ans += v[i].first * min((ll)n, v[i].second);
    n -= min((ll)n, v[i].second);
  }
  cout << ans << '\n';
  return 0;
}
