#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repab(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
#define endl "\n"

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

//--//--//--//--//--//--//--//--//--//--//--//

int n, k;
int s[20];
ll dp[200001];
ll ans = 0;

int main(){
  cin >> n >> k;
  rep(i, k){
    int l, r;
    cin >> l >> r;
    s[2*i] = l;
    s[2*i+1] = r;
  }

  rep(i, n){
    dp[i] = 0;
  }

  dp[1] = 1;
  rep(p, n){
    rep(i, k){
      for(int j=s[2*i]; j<=s[2*i+1]; j++){
        if(i+1 + j <= n){
          dp[i+1 + j] += dp[i+1];
          dp[i+1 + j] =% 998244353;
        }
      }
    }
  }

  

  cout << dp[n] % 998244353 << endl;

  return 0;
}
