//////////////////////////
//      _        ____   //
//  U  /"\  u U /"___|  //
//   \/ _ \/  \| | u    //
//   / ___ \   | |/__   //
//  /_/   \_\   \____|  //
//   \\    >>  _// \\   //
//  (__)  (__)(__)(__)  //
//  Compro by NULL_CT©  //
//////////////////////////
// STL libs
#include <algorithm>
#include <array>
#include <bits/stdint-intn.h>
#include <bitset>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

// Boost
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/irange.hpp>

#define ALL(LIST) (LIST.begin()), (LIST.end())

using namespace std;
using boost::irange;
using boost::multiprecision::cpp_int;

constexpr int64_t MOD = 1000000007;

vector<int64_t> divisor(const int64_t &_n) {
  vector<int64_t> head, tail;
  for (int64_t i = 1; i * i <= _n; i++) {
    if (_n % i == 0) {
      head.push_back(i);
      if (i * i != _n)
        tail.push_back(_n / i);
    }
  }
  head.insert(head.end(), tail.rbegin(), tail.rend());
  return head;
}

int64_t kadanes(const vector<int64_t> &_ls) {
  int64_t highestMax = 0, currentMax = 0, length = _ls.size();
  for (int64_t i = 0; i < length; i++) {
    currentMax = max(_ls[i], currentMax + _ls[i]);
    highestMax = max(highestMax, currentMax);
  }
  return highestMax;
}

void execution();

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  // cout<<fixed<<setprecision(20);

  execution();
  return 0;
}

//--------------------------------------------------------------
void execution() {
  int n, k;
  cin >> n >> k;

  vector<int> l(k), r(k),b;
  for (int i : irange(k)){
    cin >> l[i] >> r[i];
    for(int j=l[i]+1;j<r[i];j++){
      b.push_back(j);
    }
  }

  vector<int> decoy,uni;
  vector<int> dp(n, 0);
  set_union(ALL(l), ALL(r), inserter(decoy, decoy.end()));
  set_union(ALL(decoy), ALL(b), inserter(uni, uni.end()));

  sort(ALL(uni));

  dp[0] = 1;
  for (int i : irange(n)) {
    if (0 < dp[i]) {
      for (int num : uni) {
        if (dp.size() > i + num) {
          dp[i+num]%=998244353;
          dp[i]%=998244353;
          dp[i + num] += dp[i];
          dp[i+num]%=998244353;
        }
      }
    }
  }
  cout << dp[dp.size() - 1] << "\n";
}
