#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long MAX = 100000000000;
long long MOD = 998244353;
long long dp[200010];
void solve() {
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  ;
  set<long long> s;
  for (long long i = (0); i < (k); i++) {
    long long n1;
    cin >> n1;
    long long n2;
    cin >> n2;
    ;
    for (long long j = (n1); j < (n2 + 1); j++) {
      s.insert(j);
    }
  }
  vector<long long> v;
  for (auto i : s) {
    v.push_back(i);
  }
  dp[1] = 1;
  for (long long j = (2); j < (n + 1); j++) {
    for (long long i = (0); i < (v.size()); i++) {
      dp[j] = (dp[j] + (j - v[i] >= 1 ? dp[j - v[i]] : 0));
      if (dp[j] >= MOD) dp[j] -= MOD;
    }
  }
  cout << dp[n];
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long test = 1;
  while (test--) {
    solve();
  }
}
