링크 : https://www.acmicpc.net/problem/1049
/*
문제 : 기타줄
링크 : https://www.acmicpc.net/problem/1049
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int N, M;
cin >> N >> M;
vector<int> v;
vector<int> many_set;
vector<int> one_set;
for(int i = 0; i < M; i++){
int many, one;
int q, r;
cin >> many >> one;
many_set.push_back(many);
one_set.push_back(one);
}
sort(many_set.begin(), many_set.end());
sort(one_set.begin(), one_set.end());
if(N < 6){
if(many_set[0] < one_set[0] * N) cout << many_set[0];
else cout << one_set[0] * N;
}
else{
int q = N / 6;
int r = N % 6;
int a = many_set[0] * q + r * one_set[0];
int b = 0;
if(r == 0) b = many_set[0] * q;
else b = many_set[0] * (q + 1);
int c = one_set[0] * N;
if(a <= b && a <= c) cout << a;
else if(b <= a && b <= c) cout << b;
else cout << c;
}
return 0;
}