#include <bits/stdc++.h>
using namespace std;
void Print2DVector(vector<vector<int>>& v) {
  unsigned long long i, j;
  for (i = 0; i < v.size(); i++) {
    for (j = 0; j < v[i].size(); j++) {
      cout << v[i][j];
      if (j == v[i].size() - 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }
}
void PrintVector(vector<int>& v) {
  unsigned long long i;
  for (i = 0; i < v.size(); i++) {
    cout << v[i];
    if (i == v.size() - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}
void PrintArr(int* a, unsigned long long N) {
  unsigned long long i;
  for (i = 0; i < N; i++) {
    cout << a[i];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}
void PreProcessTables() {
  unsigned long long i, j;
  for (i = 0; i < 0; i++) {
    for (j = 0; j < 0; j++) {
      break;
    }
    break;
  }
}
void TC(int t) {
  unsigned long long mod_val = 998244353;
  unsigned long long dp[200001] = {0};
  unsigned long long N, K, L, R;
  cin >> N >> K;
  set<unsigned long long> s;
  for (unsigned long long i = 0; i < K; i++) {
    cin >> L >> R;
    for (unsigned long long j = L; j <= R; j++) {
      s.insert(j);
    }
  }
  dp[1] = 1;
  for (unsigned long long i = 2; i < N + 1; i++) {
    for (auto j : s) {
      if (j < i) {
        dp[i] += dp[i - j];
      }
    }
    dp[i] %= mod_val;
  }
  cout << dp[N] << endl;
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  PreProcessTables();
  int T = 1, t;
  for (t = 1; t <= T; t++) {
    TC(t);
  }
  return 0;
}
