#include <bits/stdc++.h>
using namespace std;
int main() {
  int mod = 998244353;
  int n, target;
  cin >> target >> n;
  target--;
  vector<int> c;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    for (int ii = a; ii <= b; ii++) {
      c.push_back(ii);
    }
  }
  vector<int> dp(target + 1, 0);
  dp[0] = 1;
  for (int i = 1; i <= target; i++) {
    for (int j = 0; j < (int)c.size(); j++) {
      if (i - c[j] >= 0) {
        (dp[i] += dp[i - c[j]]) %= mod;
      }
    }
  }
  cout << dp[target] << endl;
}
