#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)


void run() {
  const i64 mod{998244353};
  i64 n, k;
  cin >> n >> k;
  vector<i64> ls(k), rs(k);
  rep(i, 0, k){cin >> ls[i] >>rs[i];}
  vector<i64>counts(n);
  counts[0] = 1;
  rep(i, 1, n){
    rep(ik, 0, k){
      rep(is, ls[ik], rs[ik] + 1){
        if(0<=i-is){
          counts[i] += counts[i-is];
          counts[i] %= mod;
        }
      }
    }
  }
  cout << counts[size(counts) - 1] << endl;
}

int main() {
  cin.tie(nullptr);
  run();
  return 0;
}
