#include <bits/stdc++.h>
using namespace std;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;
const int maxN = 2e3;
const int INF = 1e9 + 7;
const long long LL_INF = 1e18 + 11;
using namespace std;
long long n, m, ans, a[maxN], b[maxN], W;
pair<long long, long long> w[maxN];
void file() {
  freopen("numbers.in", "r", stdin);
  freopen("numbers.out", "w", stdout);
}
void boost() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  boost();
  cin >> W >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
    w[i] = make_pair(b[i], a[i]);
  }
  sort(w + 1, w + n + 1);
  for (int i = n; i >= 1; i--) {
    ans += w[i].first * min(w[i].second, W);
    W -= min(w[i].second, W);
    if (W <= 0ll) {
      cout << ans;
      exit(0);
    }
  }
  cout << ans;
}
