#include <bits/stdc++.h>
using namespace std;
bool compare(vector<int>& a, vector<int>& b) {
  if (a[0] > b[0]) return true;
  return false;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > temp;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    vector<int> t;
    t.push_back(b);
    t.push_back(a);
    temp.push_back(t);
  }
  sort(temp.begin(), temp.end(), compare);
  int i = 0;
  unsigned long long sol = 0;
  while (i < m && n > 0) {
    if (temp[i][1] > n) {
      sol += ((unsigned long long)n * (unsigned long long)temp[i][0]);
      n = 0;
    } else {
      sol += (unsigned long long)temp[i][1] * (unsigned long long)temp[i][0];
      n -= temp[i][1];
    }
    i++;
  }
  cout << sol << endl;
}
