#include <bits/stdc++.h>
using namespace std;
const long long M = 998244353;
vector<long long> fac(300001);
vector<long long> ifac(300001);
long long mpow(long long x, long long n) {
  long long ans = 1;
  while (n != 0) {
    if (n & 1) ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}
long long comb(long long a, long long b) {
  if (a == 0 && b == 0) return 1;
  if (a < b || a < 0) return 0;
  long long tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}
vector<int> v;
long long int superans = 0;
void calc(vector<int> numbers) {
  cout << "1"
       << " = " << 1 << endl;
  int a = 0;
  int b = numbers.size();
  for (int i = 0; i < numbers.size(); i++) {
    a += numbers.at(i);
  }
  a += b - 1;
  cout << "("
       << "a"
       << ", "
       << "b"
       << ") = (" << a << ", " << b << ")\n";
  ;
  superans += comb(a, b);
  superans %= 998244353;
}
void minus1(int nownum, int vnum, vector<int> numbers) {
  cout << "("
       << "nownum"
       << ", "
       << "vnum"
       << ") = (" << nownum << ", " << vnum << ")\n";
  ;
  cout << "(nownum + v.at(vnum) - 1) / v.at(vnum)"
       << " = " << (nownum + v.at(vnum) - 1) / v.at(vnum) << endl;
  for (int i = 0; i < (nownum + v.at(vnum) - 1) / v.at(vnum); i++) {
    cout << "("
         << "\"rep\""
         << ", "
         << "i"
         << ") = ("
         << "rep"
         << ", " << i << ")\n";
    ;
    cout << "("
         << "vnum"
         << ", "
         << "v.at(vnum)"
         << ") = (" << vnum << ", " << v.at(vnum) << ")\n";
    ;
    cout << "nownum - i * v.at(vnum)"
         << " = " << nownum - i * v.at(vnum) << endl;
    if (i > 0) {
      cout << "i"
           << " = " << i << endl;
      numbers.push_back(i);
    }
    if (nownum - i * v.at(vnum) == 0) {
      cout << "("
           << "vnum"
           << ", "
           << "\"calc\""
           << ") = (" << vnum << ", "
           << "calc"
           << ")\n";
      ;
      calc(numbers);
    } else {
      int xx = nownum - i * v.at(vnum);
      if (v.size() > vnum + 1) {
        vnum++;
        return minus1(xx, vnum, numbers);
      }
    }
  }
  return;
}
int main() {
  fac[0] = 1;
  ifac[0] = 1;
  for (long long i = 0; i < 300000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M;
    ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M;
  }
  long long int n, k;
  cin >> n >> k;
  int l, r;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    for (int j = l; j < r + 1; j++) {
      v.push_back(j);
    }
  }
  sort(v.begin(), v.end(), greater<int>());
  vector<int> v2;
  minus1(n, 0, v2);
  cout << superans << endl;
  return 0;
}
