#include <bits/stdc++.h>
namespace patch {
template <typename T>
std::string to_string(const T& n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}
}  // namespace patch
using namespace std;
int main() {
  long long int N, M;
  cin >> N >> M;
  pair<long long int, long long int> pr[30];
  for (int i = 0; i < M; i++) {
    cin >> pr[i].second >> pr[i].first;
  }
  sort(pr, pr + M);
  long long int res = 0;
  for (int i = M - 1; i >= 0 && N; i--) {
    if (N >= pr[i].second) {
      N -= pr[i].second;
      res += pr[i].second * pr[i].first;
    } else {
      res += pr[i].first * N;
      N = 0;
    }
  }
  cout << res;
  return 0;
}
