#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
long long k;
cin >> k;
long long diff[4*200005];
memset(diff,0,sizeof diff);
vector<pair<long long,long long> > v;
for(long long i = 0 ; i < k ; i++) {
long long x;
cin >> x;
long long y;
cin >> y;
v.push_back({x,y});
}
diff[0]=0;
diff[1]=1;
long long last=0;
for(long long i=1; i<=n+5; i++) {
if(i>2) {
diff[i]+=diff[i-1];
}
long long cur = diff[i]%998244353;
for(long long j=0; j<v.size(); j++) {
diff[i+v[j].first]+=cur;
diff[i+v[j].second+1]-=cur;
}
}
cout << diff[n]%998244353 << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50MzJfdCBtYWluKCkgewoKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwoKICAgIGNpbi50aWUoMCk7CgogICAgbG9uZyBsb25nIG47CgogICAgY2luID4+IG47CgogICAgbG9uZyBsb25nIGs7CgogICAgY2luID4+IGs7CgogICAgbG9uZyBsb25nIGRpZmZbNCoyMDAwMDVdOwoKICAgIG1lbXNldChkaWZmLDAsc2l6ZW9mIGRpZmYpOwoKICAgIHZlY3RvcjxwYWlyPGxvbmcgbG9uZyxsb25nIGxvbmc+ID4gdjsKCiAgICBmb3IobG9uZyBsb25nIGkgPSAwIDsgaSA8IGsgOyBpKyspIHsKCiAgICAgICAgbG9uZyBsb25nIHg7CgogICAgICAgIGNpbiA+PiB4OwoKICAgICAgICBsb25nIGxvbmcgeTsKCiAgICAgICAgY2luID4+IHk7CgogICAgICAgIHYucHVzaF9iYWNrKHt4LHl9KTsKCiAgICB9CgogICAgZGlmZlswXT0wOwoKICAgIGRpZmZbMV09MTsKCiAgICBsb25nIGxvbmcgbGFzdD0wOwoKICAgIGZvcihsb25nIGxvbmcgaT0xOyBpPD1uKzU7IGkrKykgewoKICAgICAgICBpZihpPjIpIHsKCiAgICAgICAgICAgIGRpZmZbaV0rPWRpZmZbaS0xXTsKCiAgICAgICAgfQoKICAgICAgICBsb25nIGxvbmcgY3VyID0gZGlmZltpXSU5OTgyNDQzNTM7CgogICAgICAgIGZvcihsb25nIGxvbmcgaj0wOyBqPHYuc2l6ZSgpOyBqKyspIHsKCiAgICAgICAgICAgIGRpZmZbaSt2W2pdLmZpcnN0XSs9Y3VyOwoKICAgICAgICAgICAgZGlmZltpK3Zbal0uc2Vjb25kKzFdLT1jdXI7CgogICAgICAgIH0KCiAgICB9CgogICAgY291dCA8PCBkaWZmW25dJTk5ODI0NDM1MyA8PCAnXG4nOwoKICAgIHJldHVybiAwOwoKfQoK