/* Everything happens for a reason.
Be patient, things will be at their rightful place.
It was meant to happen this way, accept it.
And now decide what you can do about it.
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ip pair<ll,ll>
#define vii vector<ll>
#define vpp vector<ip>
#define vdd vector<ld>
#define vb vector<bool>
#define pi  pair<ll,ip>
#define sc(x) scanf("%lli",&x)
#define c(x) cin >> x
#define fo(i,k,n) for( int i=k;i<n;i++)
#define hu 200010
#define pq priotity_queue<ll>
#define pqs priority_queue<ll,vii,greater<ll>>
#define ppq priority_queue<ip,vpp,greater<ip>>
#define INF INT_MAX
#define ff first
#define ss second
using namespace std;
const ll M = 1000000000+7;
//Grid Movement
ll dx[] = {-1, 0, 1, 0};
ll dy[] = {0, -1, 0, 1};

ld Pi= acos(-1);

ll lcm(ll a,ll b)
{
    return (a*b)/(__gcd(a,b));
}

ll mex(ll x, ll y) 
{ 
	ll res = 1;	  
	x = x % M; 
	if (x == 0) return 0; 
	while (y > 0) 
	{ 
		if (y & 1) 
		res = (res*x) % M; 
		y = y>>1; 
		x = (x*x) % M; 
	} 
	return res; 
} 

bool comp(ll comp1,ll comp2)
{
    return comp1>comp2;
}

void yes()
{
    printf("YES\n");
}

void no()
{
    printf("NO\n");
}

ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
 
    if (m == 1)
      return 0;
 
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
 
    if (x < 0)
       x += m0;
 
    return x;
}

void sieve(ll n)
{
    vii primes(n+1);
    vb is_prime(n+1);
	is_prime.resize(n+1);
	primes.resize(n+1);
 
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i<=n; i++)
	{
	    if(is_prime[i])
	    {
	    	primes.pb(i);
	        for (int j = i*i; j<=n; j+=i)
	            is_prime[j] = false;
	    }
	}
}

void solve()
{
    ll n,k;
    sc(n);
    sc(k);
    vii vec;
    fo(i,0,n)
    {
        ll x,y;
        sc(x);
        sc(y);
        vec.pb(x);
        vec.pb(y);
    }
    sort(vec.begin(),vec.end());
    auto se = unique(vec.begin(),vec.end());
    vec.resize(distance(vec.begin(), se)); 
 /*   for(auto it:vec) cout << it << " ";
    cout <<endl;
    */
    ll dis[n+1]={0};
    dis[1] = 0;
    for(auto it:vec)
    {
        if(it<n) dis[it+1]=1;
    }
    ll cnt=0;
    fo(i,1,n+1)
    {
        ll ans = 0;
        for(auto it:vec)
        {
            if(it>=i)break;
            ans+=dis[i-it];
            cnt++;
        }
        dis[i]+=ans;
    }
  //  cout << cnt << endl;
    printf("%lli ",dis[n]);
    
}

int main()
{
//	ios_base::sync_with_stdio(0); cin.tie(0);
    ll t=1;
//    sc(t);
    while(t--) solve();
}



