#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 long long N,M; int main(){ cin>>N>>M; vector r,m; map mp; rep(i,M){ long long b,c; cin>>b>>c; c += b * 10000; c %= b; if(mp.count(b)){ if(mp[b]!=c){ cout<<"NaN"<> rs; for(auto a:mp){ rs.emplace_back(a.first,a.second); } reverse(rs.begin(),rs.end()); for(long long i=0;i<=N;i++){ bool f = true; rep(j,rs.size()){ if(i%rs[j].first!=rs[j].second){ f = false; break; } } if(f){ cout<