#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
using namespace std;
long long int t, n, u, x, y, k;
const long long int N = 100001;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  t = 1;
  while (t--) {
    cin >> n >> k;
    vector<long long int> a;
    for (int i = 0; i < k; ++i) {
      cin >> x >> y;
      for (int j = x; j <= y; ++j) a.push_back(j);
    }
    long long int dp[n + 1];
    sort(a.begin(), a.end());
    memset(dp, 0, sizeof dp);
    dp[1] = 1;
    for (int i = 2; i <= n; ++i) {
      for (int j = 0; j < a.size(); ++j) {
        if (i >= a[j])
          dp[i] = (dp[i] + dp[i - a[j]]) % mod;
        else
          break;
      }
    }
    cout << dp[n] << endl;
  }
}
