#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> dp(n);
  dp[0] = 1;
  vector<pair<int, int>> intervals;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    intervals.push_back({l, r});
  }
  for (int i = 1; i < dp.size(); i++) {
    for (int j = 0; j < i; j++) {
      int d = i - j;
      for (auto interval : intervals) {
        if (interval.first <= d && d <= interval.second) {
          dp[i] = (dp[i] + dp[j]) % MOD;
          break;
        }
      }
    }
  }
  cout << dp[dp.size() - 1] << endl;
}
