#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long int n, k;
  cin >> n >> k;
  long long int a[k][2];
  long long int dp[n + 5];
  vector<long long int> v;
  memset(dp, 0, sizeof(dp));
  for (long long int i = 0; i < k; i++) {
    cin >> a[i][0] >> a[i][1];
    for (long long int j = a[i][0]; j <= a[i][1]; j++) v.push_back(j);
  }
  sort(v.begin(), v.end());
  dp[0] = 1;
  long long int sum = n - 1;
  for (long long int i = 1; i <= sum; i++) {
    for (long long int j = 0; j < v.size(); j++) {
      if (i >= v[j])
        dp[i] = (dp[i] + dp[i - v[j]]) % 998244353;
      else
        break;
    }
  }
  cout << dp[sum] << endl;
}
