#include <bits/stdc++.h>
using namespace std;
int a[10007], b[10007], f[10007];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int h, n;
  cin >> h >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
  for (int i = 1; i <= h; ++i) f[i] = 1e9;
  f[0] = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= h; ++j) {
      int x = max(0, j - a[i]);
      f[j] = min(f[j], f[x] + b[i]);
    }
  cout << f[h];
  return 0;
}
