#include <bits/stdc++.h>
using namespace std;
vector<int> s;
vector<unsigned long long int> dp;
vector<unsigned long long int> dpsum;
vector<int> l;
vector<int> r;
vector<int> tmp;
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    l.push_back(t1);
    r.push_back(t2);
  }
  dp.resize(n + 1, 0);
  dpsum.resize(n + 1, 0);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      int ll = i - r[j];
      ll = max(ll, 1);
      int rr = i - l[j];
      if (rr < 0) continue;
      dp[i] += dpsum[rr] - dpsum[ll - 1];
    }
    dpsum[i] = dpsum[i - 1] + dp[i];
  }
  cout << dp[n] % 998244353 << endl;
}
