#include <bits/stdc++.h>
long long dp[200100];
using namespace std;
int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  pair<int, int> segments[12];
  for (int i = 0; i < k; i++) {
    cin >> segments[i].first >> segments[i].second;
  }
  sort(segments, segments + k);
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    bool brejk = 0;
    for (int seg_num = 0; seg_num < k; seg_num++) {
      for (int j = segments[seg_num].first; j <= segments[seg_num].second;
           j++) {
        if (j > i) {
          brejk = 1;
          break;
        }
        dp[i] += dp[i - j];
        if (dp[i] >= 998244353) dp[i] -= 998244353;
      }
      if (brejk) break;
    }
  }
  cout << dp[n - 1];
  return 0;
}
