#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long seg[(200010) * 2] = {0};
long long get(long long ind) {
  ind += (200010);
  long long sum = 0;
  sum += seg[ind];
  while (true) {
    ind /= 2;
    if (ind == 0) break;
    sum += seg[ind];
  }
  return sum;
}
void add(long long l, long long r, long long x) {
  l += (200010);
  r += (200010);
  while (l < r) {
    if (l % 2 == 1) {
      seg[l] += x;
      seg[l] %= MOD;
      l++;
    }
    l /= 2;
    if (r % 2 == 1) {
      seg[r - 1] += x;
      seg[r - 1] %= MOD;
      r--;
    }
    r /= 2;
  }
}
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long>> v(k);
  for (int i = 0; i < k; ++i) {
    long long l, r;
    cin >> l >> r;
    v[i] = make_pair(l, r);
  }
  vector<long long> a(n + 1, 0);
  add(1, 2, 1);
  for (int i = 1; i < n; ++i) {
    for (auto p : v) {
      long long x = get(i);
      int l = p.first + i;
      if (l > n) continue;
      int r = min(n + 1, p.second + i + 1);
      add(l, r, x);
    }
  }
  cout << get(n) << endl;
}
