#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
const long long mod = 998244353;
const double PI = 3.14159265358979323846;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
long long sq[1000010];
int main() {
  int N, K;
  set<int> st;
  cin >> N >> K;
  for (int i = 0; i < (K); i++) {
    int l, r;
    cin >> l >> r;
    for (int i = l; i <= r; i++) st.insert(i);
  }
  sq[1] = 1;
  for (int i = 1; i <= N; i++) {
    for (auto itr : st) {
      sq[i + itr] += sq[i];
      sq[i] %= mod;
    }
  }
  cout << sq[N] << endl;
  return 0;
}
