#include <bits/stdc++.h>
using namespace std;
bool sortrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<pair<int, int>> v;
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(b, a));
  }
  sort(v.begin(), v.end(), sortrev);
  int sum = 0;
  for (auto x : v) {
    if (n < x.second) {
      sum += n * x.first;
      break;
    }
    sum += x.first * x.second;
    n -= x.second;
  }
  cout << sum;
}
