#include <bits/stdc++.h>
using namespace std;
bool desc(pair<long long, long long> a, pair<long long, long long> b) {
  return a.second > b.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int i, j, n, m, cont = 0, p, q, d, mn, sum = 0, k, a, b, diff, z, w,
                            sum2 = 0, c, x, y, mx, first, val, ans, s1;
  cin >> n >> m;
  vector<pair<long long, long long>> v;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  sort(v.begin(), v.end(), desc);
  for (i = 0; i < m; i++) {
    mn = min(n, v[i].first);
    n -= mn;
    cont += (v[i].second * mn);
  }
  cout << cont;
}
