using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class d{
    public static void Main(){
        int div = 998244353;
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int k = int.Parse(str[1]);
        var list = new List<int>();
        for(int i=0; i<k; i++){
            int[] range = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            for(int j=range[0]; j<=range[1]; j++){
                list.Add(j);
            }
        }
        int[] pos = new int[n];
        pos[0] = 1;
        /*Queue<int> queue = new Queue<int>();
        queue.Enqueue(0);
        while(queue.Count > 0){
            int cur = queue.Dequeue();
            foreach(int v in list){
                if((v + cur) < n){
                    pos[v+cur] = (pos[v+cur] + pos[cur]) % div;
                    Console.WriteLine("----{0} {1}----",cur, v);
                    Console.WriteLine(string.Join(" ",pos));
                    queue.Enqueue(v+cur);
                }
            }

        }*/
        var sorted = new SortedSet<int>();
        sorted.Add(0);
        while(sorted.Count > 0){
            int cur = sorted.Min;
            sorted.Remove(cur);
            foreach(int v in list){
                if((v + cur) < n){
                    pos[v+cur] = (pos[v+cur] + pos[cur]) % div;
                    sorted.Add(v+cur);
                }
            }

        }
        //Console.WriteLine(string.Join(" ",pos));
        Console.WriteLine(pos[n-1]);
    }
}
