#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main(int argc, char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  const ll mod = 998244353;
  int n, k;
  cin >> n >> k;
  set<pii> check;
  for (int i = 0; i < k; i++) {
    int l, r;
    cin >> l >> r;
    check.insert(make_pair(l, r));
  }
  vector<ll> point(n, 0);
  point[0] = 1;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (point[j] == 0) {
        continue;
      }
      int diff = i - j;
      for (auto it = check.begin(); it != check.end(); it++) {
        if (diff >= it->first && diff <= it->second) {
          point[i] += point[j];
          break;
        } else if (diff < it->first) {
          break;
        }
      }
    }
  }
  cout << point[n - 1] % mod << endl;
  return 0;
}
