#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main() {
	int H, N;
	cin >> H >> N;
	vector<int> dp(H + 1, INF);
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		for (int j = 0; j < H; j++) {
			int nj = min(j + a, H);
			dp[nj] = min(dp[nj], dp[j] + b);
		}
	}

	cout << dp[H] << endl;
	
}