#include <bits/stdc++.h>
using namespace std;
const int Inf = 2000000007;
const int BIG_NUM = 1e9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i].second >> a[i].first;
  }
  sort(a.begin(), a.end());
  for (int i = m - 1; i > -1; i--) {
    ans += a[i].first * min(a[i].second, n);
    n -= min(a[i].second, n);
  }
  cout << ans << "\n";
  return 0;
}
