#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f;
int MOD = 998244353;
int tc;
int n, k, sz;
pair<long long, long long> segs[N];
vector<long long> segments;
long long mem[N];
long long solve(long long pos) {
  if (pos == n - 1) return 1;
  if (mem[pos] != -1) return mem[pos];
  long long res = 0;
  for (int i = 0; i < segments.size(); i++) {
    if (pos + segments[i] < n) {
      pos += segments[i];
      res += (solve(pos));
      res %= MOD;
      pos -= segments[i];
    }
  }
  return mem[pos] = res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  memset(mem, -1, sizeof mem);
  for (int i = 0; i < k; i++) cin >> segs[i].first >> segs[i].second;
  sort(segs, segs + k);
  for (int i = 0; i < k; i++) {
    for (int j = segs[i].first; j <= segs[i].second; j++) segments.push_back(j);
  }
  cout << solve(0) << endl;
  return 0;
}
