#include <bits/stdc++.h>
long long gcd(long long a, long long b) {
  long long temp;
  while (b > 0) {
    temp = a % b;
    a = b;
    b = temp;
  }
  return a;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long power(long long x, long long b, long long m) {
  long long p = 1;
  while (b > 0) {
    if (b & 1) {
      p = p * x;
      p %= m;
    }
    b >>= 1;
    x *= x;
    x %= m;
  }
  return p % m;
}
long long m = 998244353;
long long dp[1000000];
using namespace std;
void solve() {
  long long n, k;
  cin >> n >> k;
  set<int> s;
  while (k--) {
    int x, y;
    cin >> x >> y;
    for (int i = x; i <= y; i++) s.insert(i);
  }
  memset(dp, 0, sizeof(dp));
  dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    for (auto jump : s) {
      if (i >= jump) {
        dp[i] = (dp[i] + dp[i - jump] + 10LL * m) % m;
      } else {
        break;
      }
    }
  }
  cout << dp[n] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
