#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int INF=1e10;
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)==2&&n)
{
int ans=INF;
for(int i=0; i<m; i++)
{
int u,d;
scanf("%d%d",&u,&d);
int x=(n*d)/(u+d)+1;
int y=(u+d)*x-n*d;
ans=min(ans,y);
}
printf("%d\n",ans);
}
return 0;
}
UVA 1648(p346)----Business Center
最新推荐文章于 2020-09-06 14:53:31 发布