#include <bits/stdc++.h>
using namespace std;
bool compare(pair<long long, long long>& p1, pair<long long, long long>& p2) {
  return p1.second > p2.second;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  std::vector<pair<long long, long long> > v(m);
  for (int i = 0; i < m; i += 1) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end(), compare);
  long long noOfbags = 0;
  long long matches = 0;
  for (auto it : v) {
    if (noOfbags + it.first <= n) {
      noOfbags += it.first;
      matches += (it.first * it.second);
    } else {
      long long diff = n - noOfbags;
      if (diff <= it.first) {
        noOfbags += diff;
        matches += (diff * it.second);
      }
    }
  }
  cout << matches << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
