#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.second > p2.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<pair<long long, long long> > match;
  long long x, y;
  cin >> x >> y;
  for (long long i = 0; i < y; i++) {
    long long a, b;
    cin >> a >> b;
    match.push_back(make_pair(a, b));
  }
  sort(match.begin(), match.end(), comp);
  long long count = 0, sum = 0, i = 0;
  while (count < x && i < y) {
    if (match[i].first > 0) {
      match[i].first--;
      count++;
      sum += match[i].second;
    } else {
      i++;
    }
  }
  cout << sum;
  return 0;
}
