/*

                         YATIN KWATRA                   _03_08_14


Let's Hoop..

------------------------------------------------

           o
 /|   o         o
 \|=--            o
    ##
                    \\
                 /   \O
                O_/   T
                T    /|
                |\  | |
 _______________|_|________

------------------------------------------------

o- - -  \o          __|
   o/   /|          vv`\
  /|     |              |
   |    / \_            |
  / \   |               |
 /  |                   |


------------------------------------------------

HOOPER_4_LYF..

*/

// AC BAKSHI RABBA
/*

                         YATIN KWATRA                   _03_08_14


Let's Hoop..

------------------------------------------------

           o
 /|   o         o
 \|=--            o
    ##
                    \\
                 /   \O
                O_/   T
                T    /|
                |\  | |
 _______________|_|________

------------------------------------------------

o- - -  \o          __|
   o/   /|          vv`\
  /|     |              |
   |    / \_            |
  / \   |               |
 /  |                   |


------------------------------------------------

HOOPER_4_LYF..

*/

// AC BAKSHI RABBA

// #pragma GCC optimize "trapv"

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll                      long long
#define int                     ll
#define FIO                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld                      long double
#define ull                     unsigned long long
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                     unordered_map
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int>
#define pll                     pair<ll,ll>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     998244353
#define MIN                     -1e9
#define pi                      3.1415926535897932384626433832795

using namespace std;
using namespace __gnu_pbds;

template<class T> using oset =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


void INPUT()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

/*
----------------------------------------------------------------

   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Read the Question and the sample test cases carefully
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible ..

----------------------------------------------------------------*/

const int N = 2e5 + 5;
const int M = 14;

int dp[N];
int a[N];
pii v[M];

void solve()
{

  int n, k, x, y;
  cin >> n >> k;

  fo(i, 0, k - 1) cin >> v[i].ff >> v[i].ss;
  fo(i, 0, n) dp[i] = 0, a[i] = 0;
  sort(v, v + k);

  a[0] = 1;

  dp[0] = 1;
  fo(i, 1, n - 1) dp[i] = a[i] - a[i - 1];

  fo(i, 0, n - 1)
  {
    if (i) x = a[i - 1] + dp[i];
    else x = 1;
    x = (x % mod + mod) % mod;

    a[i] = x;

    // so we have the no of ways to reach i , so from here
    // we will can go to any position between v[i].ff to v[i].ss
    // for all the ranges
    // we can update that beacause k is very small

    fo(j, 0, k - 1)
    {
      if ((i + v[j].ff) <= n) dp[i + v[j].ff] += x;
      if ((i + v[j].ss + 1) <= n) dp[i + v[j].ss + 1] -= x;
    }
  }

  cout << a[n - 1] << endl;
}

signed main() {

  FIO
  INPUT();

  int t;
  t = 1;
// cin >> t;

  fo(i, 0, t - 1)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 6756