#include <bits/stdc++.h>
using namespace std;
template <class T>
string tostring(T x) {
  ostringstream out;
  out << x;
  return out.str();
}
long long toint(string s) {
  istringstream in(s);
  long long x;
  in >> x;
  return x;
}
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, -1, 1, -1, 1};
int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};
int main() {
  ios_base::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > Box;
  int A, B;
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    Box.push_back(pair<int, int>(B, A));
  }
  sort(Box.begin(), Box.end());
  reverse(Box.begin(), Box.end());
  long long answer = 0;
  for (int i = 0; i < M; i++) {
    if (Box[i].second >= N) {
      answer += Box[i].first * N;
      break;
    }
    N -= Box[i].second;
    answer += Box[i].first * Box[i].second;
  }
  cout << answer << "\n";
  return 0;
}
