#include<iostream>
#include<stack>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<ctime>
#include<math.h>
#include<functional>
#include<cstring>
#include<iomanip>
#include<set>
#include<utility>
#include<limits.h>
#include<stdio.h>
typedef long long ll;
//
using namespace std;
const int maxn = 1e5 + 10;
ll a[maxn], b[maxn];
int n, k;
ll maxnum = -1;
ll sum = 0;
int BS()
{
	ll left = 0, right = maxnum;
	ll mid;
	while (left < right)
	{
		mid = (left + right) / 2;
		bool f = true;
		ll magic = k;
		for (int i = 0;i < n;i++)
		{
			ll div = b[i] - a[i]*mid;
			if (div<0) magic = magic + div;
			if (magic < 0)
			{
				f = false; break;
			}
		}
		if (!f) right = mid;
		else left = mid + 1;
	}
	return left;
}
int main()
{
	cin >> n >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	for (int i = 0;i < n;i++)
	{
		cin >> b[i];

		maxnum = max(maxnum, b[i] / a[i]);
	}
	ll res = BS();
	bool f = true;
	ll magic = k;
	for (int i = 0;i < n;i++)
	{
		ll div = b[i]  - a[i]*res;
		if (div<0) magic = magic + div;
		if (magic < 0)
		{
			f = false; break;
		}
	}
	if (magic >= sum) res += (magic / sum);
	if (f || res == 0) cout << res << endl;
	else
		cout << res - 1 << endl;
	return ~~(0 - 0);
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;

int main() {
    long long n, k, l = 1000000000, r = 0, c = 0;
    cin >> n >> k;
    vector<long long> v(n), u(n);;
    for (long long i = 0; i < n; ++i)
        cin >> v[i];
    for (long long i = 0; i < n; ++i)
        cin >> u[i];
    while (l - r > 1) {
        long long total = 0, mid = (l + r) / 2;
        for (int i = 0; i < n; ++i) {
            if (v[i] * mid >= u[i])
                total += v[i] * mid - u[i];
            if (total > k)
                break;
        }
        total > k ? l = mid : r = c = mid;
    }
    cout << c;
}


#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define ll long long
using namespace std;

int f(ll a[],ll b[],ll n,ll k,ll ans)
{
 ll i;
 ll m=k;
 for(i=0;i<n;i++){
 if(ans*a[i]>b[i]) m-=(ans*a[i]-b[i]);
 if(m<0) return -1;
 }
 if(m>=0){
    ans++;
    m=k;
    for(i=0;i<n;i++){
        if(ans*a[i]>b[i]) m-=(ans*a[i]-b[i]);
        if(m<0) return 0;
    }
    if(m>=0) return 1;
 }
}
int main()
{
ll n,k;
scanf("%lld%lld",&n,&k);
ll *a=(ll *)malloc(n*sizeof(ll));
ll *b=(ll *)malloc(n*sizeof(ll));
ll i,suma=0,sumb=0;
for(i=0;i<n;i++){
 scanf("%lld",&a[i]);
 suma+=a[i];
 }
for(i=0;i<n;i++){
 scanf("%lld",&b[i]);
 sumb+=b[i];
 }
ll _max=(sumb+k)/suma;
ll _min=b[0]/a[0];
for(i=1;i<n;i++){
  _min=min(_min,(b[i]/a[i]));
 }
ll ans;
if(f(a,b,n,k,_min)==0) ans=_min;
else if(f(a,b,n,k,_max)==0) ans=_max;
else{
  ans=(_min+_max)/2;
  while(f(a,b,n,k,ans))
    {
    if(f(a,b,n,k,ans)>0) _min=ans;
    else if(f(a,b,n,k,ans)<0) _max=ans;
    ans=(_min+_max)/2;
    }
}
printf("%lld\n",ans);
return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <math.h>
#include <iomanip>
#include <fstream>
#include <map>

typedef long long ll;
using namespace std;

int main() {
	int n,k;
	cin >> n>>k;
	vector<int> va;
	vector<int> vb;
	//vector<int> m;
	ll no = 0;
	ll x = INFINITY;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		va.push_back(a);
	}
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		vb.push_back(b);
		if (b / va[i] < x) x = b / va[i];
		//m.push_back(b / va[i]);
	}
	for (int i = 0; i < n; i++) {
		vb[i] -= x*va[i];
	}
	no += x;
	ll maxy = 10e13;
	ll miny = 0;
	ll m = 0;
	ll add = 0;
	while (miny <= maxy) {
		m = (miny+maxy) / 2 ;
		ll req = 0;
		for (int i = 0; i < n; i++) {
			req += max((ll)0,(m * va[i]) - vb[i]);
		}
		if (req <= k) {
			add = m;
			miny = m + 1;
		}
		else {
			maxy = m - 1;
		}

	}
	cout << add + no << endl;
//	system("pause");
	return 0;
}


#include<iostream>
using namespace std;
#include<math.h>
#include<map>
#include<vector>
#include<algorithm>
#define ll long long
int main()
{
	  int n,mag;
	  cin>>n>>mag;
	  int *a=new int[n];
	  int *b=new int[n];
	  for(int i=0;i<n;i++)
	  cin>>a[i];

	  for(int i=0;i<n;i++)
	  cin>>b[i];

	  int c=0;
	  while(1)
	  {
	  	int f=1;
	  	int value=0;
	  	for(int i=0;i<n;i++)
		{
		b[i]-=a[i];
		if(b[i]<0)
		f=0;
		}
		if(f==1)
		c++;
		else
		{
			for(int i=0;i<n;i++)
			{
				if(b[i]<0)
				{
				value+=-1*b[i];
				b[i]=0;
				}
			}
			if(value<=mag)
			{
				mag-=value;
				c++;
			}
			else
			break;
			if(mag==0)
			break;
		}
	     }
	     cout<<c<<endl;
	     return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<pair<int, pair<int, int>>>A(n);
	for (int i = 0; i < n; i++)
		cin >> A[i].second.first;
	for (int i = 0; i < n; i++)
	{
		cin >> A[i].second.second;
		A[i].first = A[i].second.second / A[i].second.first;
	}
	while (k)
	{
		sort(A.begin(), A.end());
		if (k >= (A[0].second.first - (A[0].second.second % A[0].second.first)))
		{
			k -= A[0].second.first - (A[0].second.second % A[0].second.first);
			A[0].first++;
			A[0].second.second += A[0].second.first - (A[0].second.second % A[0].second.first);
		}
		else
			break;
	}
	sort(A.begin(), A.end());
	cout << A[0].first;
	return 0;
}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <set>
#include <list>
#include <cmath>
#include <iterator>
#include <numeric>
#include <regex>
#include <map>
#include <limits>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <array>
#include <functional>

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))

using namespace std;

int main()
{
	int32_t n, k;
	cin >> n >> k;
	int32_t a[100];
	int32_t b[100];

	int32_t curr = 1000;

	for (int32_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (int32_t i = 0; i < n; i++)
	{
		cin >> b[i];
		curr = min(curr, b[i] / a[i]);
	}

	for (int32_t i = 0; i < n; i++)
	{
		b[i] -= curr * a[i];
	}

	while (true) {
		for (int32_t i = 0; i < n; i++)
		{
			if (b[i] < a[i]) {
				if (k >= a[i] - b[i]) {
					k -= a[i] - b[i];
					b[i] = a[i];
				}
				else {
					cout << curr << endl;
					return 0;
				}
			}
			b[i] -= a[i];
		}
		curr++;
	}

}


#include <iostream>
#include <sstream>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <set>
#include <list>
#include <cmath>
#include <iterator>
#include <numeric>
#include <regex>
#include <map>
#include <limits>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <array>
#include <functional>

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))

using namespace std;

int main()
{
	int32_t n, k;
	cin >> n >> k;
	int32_t a[1000];
	int32_t b[1000];

	int32_t curr = 1000;

	for (int32_t i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	for (int32_t i = 0; i < n; i++)
	{
		cin >> b[i];
		curr = min(curr, b[i] / a[i]);
	}

	for (int32_t i = 0; i < n; i++)
	{
		b[i] -= curr * a[i];
	}

	while (true) {
		for (int32_t i = 0; i < n; i++)
		{
			if (b[i] < a[i]) {
				if (k >= a[i] - b[i]) {
					k -= a[i] - b[i];
					b[i] = a[i];
				}
				else {
					cout << curr << endl;
					return 0;
				}
			}
			b[i] -= a[i];
		}
		curr++;
	}

}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<time.h>
#include<algorithm>
#include<map>
#include<windows.h>
#include<stdlib.h>
#include<cmath>
#include<vector>
#include <sstream>
#include<set>
#include <time.h>
#define BUG1 printf("ÙF˜”¡¢¤Ê¤¼¤À\n");
#define BUG2 printf("¤ªÇ°¤Ï¤â¤¦ËÀ¤ó¤Ç¤¤¤ë!\n");
using namespace std;

const int INF = 0x3f3f3f3f;
int need[1005], have[1005];

int main()
{
	int n, mahou;
	while (scanf_s("%d%d", &n, &mahou) != EOF)
	{
		int MIN = INF;
		for (int i = 1; i <= n; i++)
			scanf_s("%d", &need[i]);
		for (int i = 1; i <= n; i++)
			scanf_s("%d", &have[i]);
		for (int i = 1; i <= n; i++)
			MIN = min(MIN, have[i] / need[i]);
		for (int i = 1; i <= n; i++)
			have[i] -= (MIN * need[i]);
		bool flag = 1;
		while (flag)
		{
			for (int i = 1; i <= n; i++)
			{
				if (have[i] < need[i])
				{
					mahou -= need[i] - have[i];
					have[i] = 0;
				}
				else
					have[i] -= need[i];
				if (mahou < 0)
				{
					flag = 0;
					break;
				}
			}
			MIN++;
		}
		MIN--;
		printf("%d\n", MIN);
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	int n, k, x = 0;
	cin >> n >> k;
	vector<pair<int, int>>v(n);
	vector<int >s(1001);
	for (int i = 0; i < n; i++)
		cin >> v[i].first;
	for (int i = 0; i < n; i++)
		cin >> v[i].second;
	for (int i = 0; i < n; i++)
		s[v[i].second / v[i].first]++;
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if ((v[i].second / v[i].first) > (v[j].second / v[j].first))
			{
				swap(v[i].second, v[j].second);
				swap(v[i].first, v[j].first);
			}

	for (int i = 1; i <10; i++)
	{
		for (int j = 0; j < s[i]; j++)
		{
			x = v[j].first * (i + 1) - v[j].second;
			if (x <= k)
			{
				k -= x;
			}
			else
			{
				cout << i; return 0;
			}

		}
			s[i + 1] += s[i];
		}

}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	int n, k, x = 0;
	cin >> n >> k;
	vector<pair<int, int>>v(n);
	vector<int >s(30000,0);
	for (int i = 0; i < n; i++)
		cin >> v[i].first;
	for (int i = 0; i < n; i++)
		cin >> v[i].second;
	for (int i = 0; i < n; i++)
		s[v[i].second / v[i].first]++;
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if ((v[i].second / v[i].first) > (v[j].second / v[j].first))
			{
				swap(v[i].second, v[j].second);
				swap(v[i].first, v[j].first);
			}

	/*for (int i = 0; i < n; i++)
		cout << v[i].first << " "; cout << endl;
	for (int i = 0; i < n; i++)
		cout<< v[i].second << " ";
		*/
	for (int i = 1; i <=2000; i++)
	{
		for (int j = 0; j < s[i]; j++)
		{
			if (v[j].second / v[j].first == i)
				x = v[j].first * (i + 1) - v[j].second;
			else
			x = v[j].first * (i + 1) - v[j].second- (v[j].first * (i) - v[j].second);

			if (x <= k)
			{
				k -= x;
			}
			else
			{
				cout << i << " "; return 0;
			}

		}
			s[i + 1] += s[i];
		}

}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	int n, k, x = 0;
	cin >> n >> k;
	vector<pair<int, int>>v(n);
	vector<int >s(1001);
	for (int i = 0; i < n; i++)
		cin >> v[i].first;
	for (int i = 0; i < n; i++)
		cin >> v[i].second;
	for (int i = 0; i < n; i++)
		s[v[i].second / v[i].first]++;
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if ((v[i].second / v[i].first) > (v[j].second / v[j].first))
			{
				swap(v[i].second, v[j].second);
				swap(v[i].first, v[j].first);
			}

	for (int i = 0; i <1000; i++)
	{
		for (int j = 0; j < s[i]; j++)
		{
			x = v[j].first * (i + 1) - v[j].second;
			if (x <= k)
			{
				k -= x;
			}
			else
			{
				cout << i; return 0;
			}

		}
			s[i + 1] += s[i];
		}

}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	int n, k, x = 0;
	cin >> n >> k;
	vector<pair<int, int>>v(n);
	vector<int >s(1001,0);
	for (int i = 0; i < n; i++)
		cin >> v[i].first;
	for (int i = 0; i < n; i++)
		cin >> v[i].second;
	for (int i = 0; i < n; i++)
		s[v[i].second / v[i].first]++;
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if ((v[i].second / v[i].first) > (v[j].second / v[j].first))
			{
				swap(v[i].second, v[j].second);
				swap(v[i].first, v[j].first);
			}

	/*for (int i = 0; i < n; i++)
		cout << v[i].first << " "; cout << endl;
	for (int i = 0; i < n; i++)
		cout<< v[i].second << " ";
		*/
	for (int i = 1; i <1000; i++)
	{
		for (int j = 0; j < s[i]; j++)
		{
			if (v[j].second / v[j].first == i)
				x = v[j].first * (i + 1) - v[j].second;
			else
			x = v[j].first * (i + 1) - v[j].second- (v[j].first * (i) - v[j].second);

			if (x <= k)
			{
				k -= x;
			}
			else
			{
				cout << i << " "; return 0;
			}

		}
			s[i + 1] += s[i];
		}

}


#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	int n, k, x = 0;
	cin >> n >> k;
	vector<pair<int, int>>v(n);
	vector<int >s(30000,0);
	for (int i = 0; i < n; i++)
		cin >> v[i].first;
	for (int i = 0; i < n; i++)
		cin >> v[i].second;
	for (int i = 0; i < n; i++)
		s[v[i].second / v[i].first]++;
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if ((v[i].second / v[i].first) > (v[j].second / v[j].first))
			{
				swap(v[i].second, v[j].second);
				swap(v[i].first, v[j].first);
			}

	/*for (int i = 0; i < n; i++)
		cout << v[i].first << " "; cout << endl;
	for (int i = 0; i < n; i++)
		cout<< v[i].second << " ";
		*/
	for (int i = 0; i <=2000; i++)
	{
		for (int j = 0; j < s[i]; j++)
		{
			if (v[j].second / v[j].first == i)
				x = v[j].first * (i + 1) - v[j].second;
			else
			x = v[j].first * (i + 1) - v[j].second- (v[j].first * (i) - v[j].second);

			if (x <= k)
			{
				k -= x;
			}
			else
			{
				cout << i << " "; return 0;
			}

		}
			s[i + 1] += s[i];
		}

}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <random>
using namespace std;

void solve() {
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, k;
    cin >> n >> k;

    int need[1010];
    for (int i = 0; i < n; i++)
        cin >> need[i];

    int have[1010];
    for (int i = 0; i < n; i++)
        cin >> have[i];

    int l = 0, r = 1e9;
    while (l + 1 < r) {
        long long m = l + (r - l) / 2;

        long long kNeed = 0;
        for (int i = 0; i < n; i++)
            kNeed += max<long long>(0, need[i] * m - have[i]);

        if (kNeed <= k)
            l = m;
        else
            r = m;
    }

    cout << l;
}


#include <iostream>
using namespace std;

const int N = 1e3 + 9;

int ingredients, magicPowder, needed[N], have[N];

int ok(int x){
	int powder = magicPowder;
	for (int i = 0; i < ingredients; ++i){
		int neededPowder = (needed[i] * x) - have[i];
		if (neededPowder > 0) {
			powder -= neededPowder;
			if (powder < 0) return 0;
		}
	}
	return 1;
}

int binarySearch(){
	int low = 0, med, high = 4e3;
	while (low < high){
		med = (low + high + 1) >> 1;
		if (ok(med)) low = med;
		else high = med - 1;
	}
	return low;
}

int main(){
	scanf("%d %d", &ingredients, &magicPowder);
	for (int i = 0; i < ingredients; ++i)
		scanf("%d", &needed[i]);
	for (int i = 0; i < ingredients; ++i)
		scanf("%d", &have[i]);
	printf("%d\n", binarySearch());
	return 0;
}


#include <iostream>
using namespace std;

const int N = 1e3 + 9;

int ingredients, magicPowder, needed[N], have[N];

int ok(int x){
	int powder = magicPowder;
	for (int i = 0; i < ingredients; ++i){
		int neededPowder = (needed[i] * x) - have[i];
		if (neededPowder > 0) {
			powder -= neededPowder;
			if (powder < 0) return 0;
		}
	}
	return 1;
}

int binarySearch(){
	int low = 0, med, high = 1e3 + 2;
	while (low < high){
		med = (low + high + 1) >> 1;
		if (ok(med)) low = med;
		else high = med - 1;
	}
	return low;
}

int main(){
	scanf("%d %d", &ingredients, &magicPowder);
	for (int i = 0; i < ingredients; ++i)
		scanf("%d", &needed[i]);
	for (int i = 0; i < ingredients; ++i)
		scanf("%d", &have[i]);
	printf("%d\n", binarySearch());
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main()
{
#ifdef _DEBUG
	FILE* fin = freopen("in.txt","rt", stdin);
#endif

    int n, k;
    scanf("%d %d", &n, &k);

    vector<int> a(n), b(n);
    FOR(i,0,n)
        scanf("%d", &a[i]);
    FOR(i,0,n)
        scanf("%d", &b[i]);

    int cnt = 987654321;

    FOR(i,0,n)
        cnt = min(cnt, b[i]/a[i]);

    int tmp = cnt;

    while(true)
    {
        bool isPos = true;
        FOR(i,0,n)
        {
            if (a[i] * (cnt + 1) > b[i] )
            {
                if (a[i] * (cnt + 1) - b[i] < a[i])
                    k -= (a[i] * (cnt + 1) - b[i]);
                else
                    k -= a[i];
                if (k < 0)
                {
                    isPos = false;
                    break;
                }
            }
        }
        if (isPos)
            cnt++;
        else
            break;

    }

    printf("%d\n", cnt);

#ifdef _DEBUG
	fclose(fin);
#endif
	return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main()
{
#ifdef _DEBUG
	FILE* fin = freopen("in.txt","rt", stdin);
#endif

    int n, k;
    scanf("%d %d", &n, &k);

    vector<int> a(n), b(n);
    FOR(i,0,n)
        scanf("%d", &a[i]);
    FOR(i,0,n)
        scanf("%d", &b[i]);

    int cnt = 987654321;

    FOR(i,0,n)
        cnt = min(cnt, b[i]/a[i]);

    int tmp = cnt;

    while(true)
    {
        bool isPos = true;
        FOR(i,0,n)
        {
            if (a[i] * (cnt + 1) > b[i] )
            {
                if (cnt == tmp)
                    k -= a[i] * (cnt + 1) - b[i];
                else
                    k -= a[i];
                if (k < 0)
                {
                    isPos = false;
                    break;
                }
            }
        }
        if (isPos)
            cnt++;
        else
            break;

    }

    printf("%d\n", cnt);

#ifdef _DEBUG
	fclose(fin);
#endif
	return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <iostream>
#include <string>

#define mp make_pair
#define ll long long
#define pb push_back

using namespace std;

const long double PI=3.1415926535897932384626433832795;
const ll INF=1e9+7;
const long double EPS=1e-9;
const ll MOD=1000000007;
const int MAXN = 2000;

	int n;
	int k,x;
	vector <int> a,b;

bool check(int pos){
	int t=k;
	for (int i=0;i<n;i++){
		if ( pos*a[i]>b[i])
			t-=pos*a[i]-b[i];
	}
	return (t>=0) ? true : false;
}

void solve(){

	cin >> n >> k;
	for (int i=0;i<n;i++){
		cin >> x;
		a.pb(x);
	}
	for (int i=0;i<n;i++){
		cin >> x;
		b.pb(x);
	}

	int l=0,r=10000;
	while (l+1<r){
		int mid=(l+r) >> 1;
		if (check(mid) )
			l=mid;
		else
			r=mid;
	}
	cout << l;
}

int main(){

	//freopen( "cubroot.in", "r", stdin );
	//freopen( "cubroot.out", "w", stdout );
	//
	int k11=1;
//	cin >> k;
	while (k11--){
		solve();
	}
	return 0;
}


#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <iostream>
#include <string>

#define mp make_pair
#define ll long long
#define pb push_back

using namespace std;

const long double PI=3.1415926535897932384626433832795;
const ll INF=1e9+7;
const long double EPS=1e-9;
const ll MOD=1000000007;
const int MAXN = 2000;

	int n;
	int k,x;
	vector <int> a,b;

bool check(int pos){
	int t=k;
	for (int i=0;i<n;i++){
		if ( pos*a[i]>b[i])
			t-=pos*a[i]-b[i];
	}
	return (t>=0) ? true : false;
}

void solve(){

	cin >> n >> k;
	for (int i=0;i<n;i++){
		cin >> x;
		a.pb(x);
	}
	for (int i=0;i<n;i++){
		cin >> x;
		b.pb(x);
	}

	int l=0,r=1000;
	while (l+1<r){
		int mid=(l+r) >> 1;
		if (check(mid) )
			l=mid;
		else
			r=mid;
	}
	cout << l;
}

int main(){

	//freopen( "cubroot.in", "r", stdin );
	//freopen( "cubroot.out", "w", stdout );
	//
	int k11=1;
//	cin >> k;
	while (k11--){
		solve();
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <bitset>
#include <string>
#include <math.h>
#include <stack>
#include <queue>
#include <functional>
#include <conio.h>
#include <set>
#include <algorithm>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> ii;
#define FOR(i, j, n) for (int i = j; i < n; i++)
#define ROF(i, j, n) for (int i = j; i >= n; i--)
#define pp(a, b) make_pair(a, b)
#define SC(n) scanf("%d", &n)
#define PF(n) printf("%d", n)
#define PFn(n) printf("%d\n", n)
#define SC2(n, m) scanf("%d%d", &n, &m)
#define SCf(n) scanf("%lf", &n)
#define SCs(s) scanf("%s", s);
#define MAX 100010

int n, a[1005], k, b[1005];

int main() {
	SC2(n, k);
	FOR(i, 0, n) SC(a[i]);
	FOR(i, 0, n) SC(b[i]);
	int ans = 0;
	FOR(i, 1, 10001) {
		int kk = k;
		bool f = 1;
		FOR(j, 0, n) {
			if (b[j] < a[j] * i) {
				int d = i * a[j];
				if (kk >= d - b[j]) kk = kk - d + b[j];
				else {
					f = 0;
					break;
				}
			}
		}
		if (f) ans = max(ans, i);
	}
	printf("%d\n", ans);
	return 0;
}

/*
4 3
4 3 5 6
11 12 14 20
*/


#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <bitset>
#include <string>
#include <math.h>
#include <stack>
#include <queue>
#include <functional>
#include <conio.h>
#include <set>
#include <algorithm>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> ii;
#define FOR(i, j, n) for (int i = j; i < n; i++)
#define ROF(i, j, n) for (int i = j; i >= n; i--)
#define pp(a, b) make_pair(a, b)
#define SC(n) scanf("%d", &n)
#define PF(n) printf("%d", n)
#define PFn(n) printf("%d\n", n)
#define SC2(n, m) scanf("%d%d", &n, &m)
#define SCf(n) scanf("%lf", &n)
#define SCs(s) scanf("%s", s);
#define MAX 100010

int n, a[1005], k, b[1005];

int main() {
	SC2(n, k);
	FOR(i, 0, n) SC(a[i]);
	FOR(i, 0, n) SC(b[i]);
	int ans = 0;
	FOR(i, 1, 1001) {
		int kk = k;
		bool f = 1;
		FOR(j, 0, n) {
			if (b[j] < a[j] * i) {
				int d = i * a[j];
				if (kk >= d - b[j]) kk = kk - d + b[j];
				else {
					f = 0;
					break;
				}
			}
		}
		if (f) ans = max(ans, i);
	}
	printf("%d\n", ans);
	return 0;
}


#include<iostream>
#include <set>
#include<vector>
#include <algorithm>
#include<deque>

using namespace std;

struct pair1 {
	int i;
	double q;
};

bool sort_function(pair1 i, pair1 j){
	return (i.q<j.q);
}

int main() {
	int n;
	int k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	vector<int> b(n);
	for (int i = 0;i < n;i++) {
		cin >> b[i];
	}

	vector<pair1> d;
	for (int i = 0;i < n;i++) {
		d.push_back({ i,double(b[i]) / double(a[i]) });
	}
	sort(d.begin(), d.end(), sort_function);
	pair1 h;
	while (k > 0) {
		h = d[0];
		int z = b[h.i];
		b[h.i] += (k >= (a[h.i] - z % a[h.i])) ? (a[h.i] - z % a[h.i]) : k;
		k -= (k >= (a[h.i] - z % a[h.i])) ? (a[h.i] - z % a[h.i]) : k;
		d[0]={ h.i,double(b[h.i]) / double(a[h.i]) };
		sort(d.begin(), d.end(), sort_function);
	}
	int p = int(d[0].q);
	if (p > d[0].q) { p--; }
	cout << p;
	return 0;
}


#include<iostream>
#include <set>
#include<vector>
#include <algorithm>
#include<deque>

using namespace std;

struct pair1 {
	int i;
	double q;
};

bool sort_function(pair1 i, pair1 j){
	return (i.q<j.q);
}

int main() {
	int n;
	int k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	vector<int> b(n);
	for (int i = 0;i < n;i++) {
		cin >> b[i];
	}

	vector<pair1> d;
	for (int i = 0;i < n;i++) {
		pair1 v;
		v.i = i;
		v.q = double(b[i]) / double(a[i]);
		d.push_back(v);
	}
	sort(d.begin(), d.end(), sort_function);
	pair1 h;
	while (k > 0) {
		h = d[0];
		int z = b[h.i];
		b[h.i] += (k >= (a[h.i] - z % a[h.i])) ? (a[h.i] - z % a[h.i]) : k;
		k -= (k >= (a[h.i] - z % a[h.i])) ? (a[h.i] - z % a[h.i]) : k;
		d[0].q = double(b[h.i]) / double(a[h.i]);;
		sort(d.begin(), d.end(), sort_function);
	}
	int p = int(d[0].q);
	if (p > d[0].q) { p--; }
	cout << p;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;

int n,k;
struct cookie{
    int need;
    int has;
    bool operator < (const cookie &a)const{
        return (a.has / a.need) < (has / need);
    }
}cook[10010];
priority_queue<cookie>q;
int main(){
    int i,j;
    scanf("%d%d",&n,&k);
    for(i = 1; i <= n; i++){
        scanf("%d",&cook[i].need);
    }
    for(i = 1; i <= n; i++){
        scanf("%d",&cook[i].has);
        q.push(cook[i]);
    }

    while(k){
        cookie temp = q.top();
        q.pop();
        temp.has++;
        k--;
        q.push(temp);
    }
    int mincook = q.top().has/q.top().need;
    printf("%d\n",mincook);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;

int m,r;
struct cookie{
    int need;
    int has;
    bool operator < (const cookie &a)const{
        return (a.has / a.need) < (has / need);
    }
}cook[10010];
priority_queue<cookie>q;
int main(){
    int i,j;
    scanf("%d%d",&m,&r);
    for(i = 1; i <= m; i++){
        scanf("%d",&cook[i].need);
    }
    for(i = 1; i <= m; i++){
        scanf("%d",&cook[i].has);
        q.push(cook[i]);
    }

    while(k){
        cookie temp = q.top();
        q.pop();
        temp.has++;
        r--;
        q.push(temp);
    }
    int mincook = q.top().has/q.top().need;
    printf("%d\n",mincook);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;

int m,t;
struct cookie{
    int need;
    int has;
    bool operator < (const cookie &a)const{
        return (a.has / a.need) < (has / need);
    }
}cook[10010];
priority_queue<cookie>q;
int main(){
    int i,j;
    scanf("%d%d",&m,&t);
    for(i = 1; i <= m; i++){
        scanf("%d",&cook[i].need);
    }
    for(i = 1; i <= m; i++){
        scanf("%d",&cook[i].has);
        q.push(cook[i]);
    }

    while(t){
        cookie temp = q.top();
        q.pop();
        temp.has++;
        t--;
        q.push(temp);
    }
    int mincook = q.top().has/q.top().need;
    printf("%d\n",mincook);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;

int m,r;
struct cookie{
    int need;
    int has;
    bool operator < (const cookie &a)const{
        return (a.has / a.need) < (has / need);
    }
}cook[10010];
priority_queue<cookie>q;
int main(){
    int i,j;
    scanf("%d%d",&m,&r);
    for(i = 1; i <= m; i++){
        scanf("%d",&cook[i].need);
    }
    for(i = 1; i <= m; i++){
        scanf("%d",&cook[i].has);
        q.push(cook[i]);
    }

    while(r){
        cookie temp = q.top();
        q.pop();
        temp.has++;
        r--;
        q.push(temp);
    }
    int mincook = q.top().has/q.top().need;
    printf("%d\n",mincook);
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N=1005;
int a[MAX_N];
int b[MAX_N];
struct name {int np,ost,a;};
name x[MAX_N];
bool comp (name &a,name &b)
{
	return (a.np<b.np||a.np==b.np&&a.ost<b.ost);
}
int main ()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n,k;
	cin>>n>>k;
	for (int i=0;i<n;i++)
		cin>>a[i];
	for (int i=0;i<n;i++)
		cin>>b[i];
	for (int i=0;i<n;i++)
	{
		x[i].np=b[i]/a[i];
		x[i].ost=b[i]%a[i];
		x[i].a=a[i];
	}
	sort (x,x+n,comp);
	bool q=1;
	int minans=x[0].np;
	for (int i=0;;i++)
	{
		if (x[i].np==minans)
		{
			if (k>=x[i].a-x[i].ost)
			{
				k-=(x[i].a-x[i].ost);
				x[i].ost=0;
				x[i].np++;
			}
			else
			{
				break;
			}
		}
		else
		{
			minans++;
			i=0;
		}
	}
	cout<<minans;
}


#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N=1005;
int a[MAX_N];
int b[MAX_N];
struct name {int np,ost,a;};
name x[MAX_N];
bool comp (name &a,name &b)
{
	return (a.np<b.np||a.np==b.np&&a.ost<b.ost);
}
int main ()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n,k;
	cin>>n>>k;
	for (int i=0;i<n;i++)
		cin>>a[i];
	for (int i=0;i<n;i++)
		cin>>b[i];
	for (int i=0;i<n;i++)
	{
		x[i].np=b[i]/a[i];
		x[i].ost=b[i]%a[i];
		x[i].a=a[i];
	}
	sort (x,x+n,comp);
	bool q=1;
	int minans=x[0].np;
	for (int i=0;i<n;i++)
	{
		if (x[i].np==minans)
		{
			if (k>=x[i].a-x[i].ost)
			{
				k-=x[i].a-x[i].ost;
				x[i].ost=0;
				x[i].np++;
			}
			else
			{break;}
		}
		else
		{
			minans++;
			i=0;
		}
	}
	cout<<minans;
}


#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N=100005;
long long a[MAX_N];
long long b[MAX_N];
struct name {long long np,ost,a;};
name x[MAX_N];
bool comp (name &a,name &b)
{
	return (a.np<b.np||a.np==b.np&&a.ost<b.ost);
}
int main ()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	long long n,k;
	cin>>n>>k;
	for (int i=0;i<n;i++)
		cin>>a[i];
	for (int i=0;i<n;i++)
		cin>>b[i];
	for (int i=0;i<n;i++)
	{
		x[i].np=b[i]/a[i];
		x[i].ost=b[i]%a[i];
		x[i].a=a[i];
	}
	sort (x,x+n,comp);
	long long pir=x[0].np,sum=0;
	for (int i=0;i<n;i++)
	{
		if (pir==x[i].np)
		{
			if (k>=x[i].a-x[i].ost)
			{
				k-=x[i].a-x[i].ost;
				if (i==n-1)
					pir++;
			}
			else
			{
				cout<<pir;
				return 0;
			}
		}
		else
		{
			pir++;
			if (k>=sum*(x[i].np-pir+1)+x[i].a-x[i].ost)
			{
				k-=sum*(x[i].np-pir+1)+x[i].a-x[i].ost;
				pir=x[i].np;
				if (i==n-1)
					pir++;
			}
			else
			{
				pir+=k/sum;
				pir=min(pir,x[i].np);
				cout<<pir;
				return 0;
			}
		}
		sum+=x[i].a;
	}
	pir+=k/sum;
	cout<< pir;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N=100005;
long long a[MAX_N];
long long b[MAX_N];
struct name {long long np,ost,a;};
name x[MAX_N];
bool comp (name &a,name &b)
{
	return (a.np<b.np||a.np==b.np&&a.ost<b.ost);
}
int main ()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	long long n,k;
	cin>>n>>k;
	for (int i=0;i<n;i++)
		cin>>a[i];
	for (int i=0;i<n;i++)
		cin>>b[i];
	for (int i=0;i<n;i++)
	{
		x[i].np=b[i]/a[i];
		x[i].ost=b[i]%a[i];
		x[i].a=a[i];
	}
	sort (x,x+n,comp);
	long long pir=x[0].np,sum=0;
	for (int i=0;i<n;i++)
	{
		if (pir==x[i].np)
		{
			if (k>=x[i].a-x[i].ost)
			{
				k-=x[i].a-x[i].ost;
				if (i==n-1)
					pir++;
			}
			else
			{
				cout<<pir;
				return 0;
			}
		}
		else
		{
			pir++;
			if (k>=sum*(x[i].np-pir+1)+x[i].a-x[i].ost)
			{
				k-=sum*(x[i].np-pir+1)+x[i].a-x[i].ost;
				pir=x[i].np;
			}
			else
			{
				pir+=k/sum;
				cout<<pir;
				return 0;
			}
		}
		sum+=x[i].a;
	}
	pir+=k/sum;
	cout<< pir;
	return 0;
}


// ConsoleApplication13.cpp : Defines the entry point for the console application.
//
//#include"stdafx.h"
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	int n,k;
	cin >> n>>k;
	vector<int>v;
	vector<int>b;
	v.resize(n);
	b.resize(n);
	for (int i = 0;i < n;i++)
	{
		cin >> v[i];
	}
	for (int i = 0;i < n;i++)
	{
		cin >> b[i];
	}
	long long count = 0;
	bool f = 0;
	while (!f)
	{
		for (int i = 0;i < n;i++)
		{
			b[i] -= v[i];
			if (b[i] < 0)
			{
				b[i] += k;
				k = b[i];
				b[i] = 0;
			}
			if (k < 0)
			{
				f = 1;
				break;
			}
		}
		if(!f)
		 count++;
	}
	cout << count;
	return 0;
}


// ConsoleApplication13.cpp : Defines the entry point for the console application.
//

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main()
{
	int n,k;
	cin >> n>>k;
	vector<int>v;
	vector<int>b;
	v.resize(n);
	b.resize(n);
	long long sum = 0;
	for (int i = 0;i < n;i++)
	{
		cin >> v[i];
		sum += v[i];
	}
	long long q = 0;
	for (int i = 0;i < n;i++)
	{
		cin >> b[i];
		q +=b[i];
	}
	long long count = 0;
	q += k;
	while (q > sum)
	{
		q -= sum;
		count++;
	}
	cout << count;
	return 0;
}


// ConsoleApplication13.cpp : Defines the entry point for the console application.
//
//#include"stdafx.h"
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main()
{
	int n,k;
	cin >> n>>k;
	vector<int>v;
	vector<int>b;
	v.resize(n);
	b.resize(n);
	long long sum = 0;
	for (int i = 0;i < n;i++)
	{
		cin >> v[i];
	}
	long long q = 0;
	for (int i = 0;i < n;i++)
	{
		cin >> b[i];
	}
	long long count = 0;
	bool f = 0;
	while (!f)
	{
		for (int i = 0;i < n;i++)
		{
			b[i] -= v[i];
			if (b[i] < 0)
			{
				b[i] += k;
				k = b[i] - 0;
			}
			if (k < 0)
			{
				f = 1;
				break;
			}
		}
		if(!f)
		 count++;
	}
	cout << count;
	return 0;
}


// ConsoleApplication13.cpp : Defines the entry point for the console application.
//
//#include"stdafx.h"
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,k;
	cin >> n>>k;
	vector<int>v;
	vector<int>b;
	v.resize(n);
	b.resize(n);
	for (int i = 0;i < n;i++)
	{
		cin >> v[i];
	}
	for (int i = 0;i < n;i++)
	{
		cin >> b[i];
	}
	long long count = 0;
	bool f = 0;
	while (!f)
	{
		for (int i = 0;i < n;i++)
		{
			b[i] -= v[i];
			if (b[i] < 0)
			{
				b[i] += k;
				k = b[i];
				b[i] = 0;
			}
			if (k < 0)
			{
				f = 1;
				break;
			}
		}
		if(!f)
		 count++;
	}
	cout << count;
	return 0;
}


// ConsoleApplication13.cpp : Defines the entry point for the console application.
//

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main()
{
	int n,k;
	cin >> n>>k;
	int j;
	long long sum = 0;
	for (int i = 0;i < n;i++)
	{
		cin >> j;
		sum += j;
	}
	long long q = 0;
	for (int i = 0;i < n;i++)
	{
		cin >> j;
		q +=j;
	}
	long long count = 0;
	q += k;
	while (q >0)
	{
		q -= sum;
		count++;
	}
	cout << count;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <queue>
#include <utility>
#include <stack>
#include <climits>
#include <deque>
#include <map>
#include <cctype>
#define MAXN 100005
#define MAXM 1000000005
#define MAXLG 18
#define endl '\n'
const double PI = 3.1415926535897932384626433832795;
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll A[MAXN], B[MAXN];
int main() {
	//freopen("input.txt", "r", stdin);//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(12);
	cout << fixed;
	int n;
	ll c=0,sum=0,k;
	cin >> n >> k;
	for(int i = 0; i < n; ++i) cin >> A[i], sum += A[i];
	cin >> B[0];
	c = B[0]/A[0];
	for(int i = 1; i < n; ++i) cin >> B[i], c = min(c, B[i]/A[i]);
	for(int i = 0; i < n; ++i){
		B[i] -= c*A[i];
		if(A[i] > B[i]) k -= A[i]-B[i];
	}
	if(k >= 0) ++c;
	c += k/sum;
	cout << c << endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <queue>
#include <utility>
#include <stack>
#include <climits>
#include <deque>
#include <map>
#include <cctype>
#define MAXN 100005
#define MAXM 1000000005
#define MAXLG 18
#define endl '\n'
const double PI = 3.1415926535897932384626433832795;
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll A[MAXN], B[MAXN];
int main() {
	//freopen("input.txt", "r", stdin);//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(12);
	cout << fixed;
	int n;
	ll c=0,sum=0,k;
	cin >> n >> k;
	for(int i = 0; i < n; ++i) cin >> A[i];
	for(int i = 0; i < n; ++i) cin >> B[i];
	ll L = 0, R = 2*mod,mid;
	while(L <= R){
		mid = (L+R)/2;sum = k;
		for(int i = 0; sum >= 0 && i < n; ++i){
			sum -= max(mid * A[i] - B[i], (ll)0);
		}
		if(sum < 0) R = mid-1;
		else L = mid+1;
	}
	cout << R << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>

using namespace std;

long long a1[200113], a2[200113];

long long MAXN = (long long)1e9 + 13;

int main() {
    long long n, m1;
    cin >> n >> m1;
    for (long long i = 0; i < n; i++)
      cin >> a1[i];
    for (long long i = 0; i < n; i++)
      cin >> a2[i];
    long long l = 0, r = MAXN;
    while (r - l > 1) {
      long long m = (l + r) / 2;
      long long k = 0;
      for (long long i = 0; i < n; i++)
        k += max((long long)0, m * a1[i] - a2[i]);
      if (k <= m1)
        l = m;
      else
        r = m;
    }
    cout << l;
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int need[1008];
int have[1008];
int tmpp[1008];
int n,k;
int Slove(int mid)
{
    for(int i=1;i<=n;i++)
    {
        tmpp[i]=have[i]-mid*need[i];
    }
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(tmpp[i]<0)sum+=-tmpp[i];
    }
    if(sum<=k)return 1;
    else return 0;
}
int main()
{
    while(~scanf("%d%d",&n,&k))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&need[i]);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&have[i]);
        }
        int ans=0;
        int mid;
        int l=0;
        int r=10000;
        while(r>=l)
        {
            mid=(l+r)/2;
            if(Slove(mid)==1)
            {
                ans=mid;
                l=mid+1;
            }
            else
            {
                r=mid-1;
            }
        }
        printf("%d\n",ans);
    }
    //cout << "Hello world!" << endl;
    return 0;
}


#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int need[1008];
int have[1008];
int tmpp[1008];
int n,k;
int Slove(int mid)
{
    for(int i=1;i<=n;i++)
    {
        tmpp[i]=have[i]-mid*need[i];
    }
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(tmpp[i]<0)sum+=-tmpp[i];
    }
    if(sum<=k)return 1;
    else return 0;
}
int main()
{
    while(~scanf("%d%d",&n,&k))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&need[i]);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&have[i]);
        }
        int ans=0;
        int mid;
        int l=0;
        int r=10000;
        while(r>=l)
        {
            mid=(l+r)/2;
            if(Slove(mid)==1)
            {
                ans=mid;
                l=mid+1;
            }
            else
            {
                r=mid-1;
            }
        }
        printf("%d\n",ans);
    }
    cout << "Hello world!" << endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int arr[100000];
void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	int val=0,count=0;
	while(val<=k)
	{
		k=k-val;
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				 val=val+a[i]-b[i];
		}
	}
	if(val<=k)
		{
			arr[count]=1;
			count++;
	    }
	else
		break;

	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int arr[100000];
void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	int val=0,count=0;
	while(val<=k)
	{
		k=k-val;
		val=0;
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				 val=val+a[i]-b[i];
				 b[i]=0;

		}
	}
	if(val<=k)
		{
			arr[count]=1;
			count++;
	    }
	else
		break;

	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int arr[100000];

void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a;
	vector<int>b;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
	}
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		b.push_back(x);
	}
	int val=0;
	int count=0;
	while(val<=k)
	{
		k=k-val;
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				val=val+a[i]-b[i];
		}
	}
	if(flag)
		{
			arr[count]=1;
			count++;
	    }
	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int arr[100000];
void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	int val=0,count=0;
	while(val<=k)
	{
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				val=val+a[i]-b[i];
		}
	}
	if(flag)
		{
			arr[count]=1;
			count++;
	    }
			k=k-val;
			val=0;
	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int arr[100000];
void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	int val=0,count=0;
	while(val<=k)
	{
		k=k-val;
		val=0;
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				 val=val+a[i]-b[i];
				 b[i]=0;

		}
	}
	if(val<=k)
		{
			arr[count]=1;
			count++;
	    }
	else
		break;

	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	if(start!=0)
	cout<<start+1;
	else
		cout<<0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int arr[100000];
void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	int val=0,count=0;
	while(val<=k)
	{
		k=k-val;
		val=0;
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				 val=val+a[i]-b[i];
				 b[i]=0;

		}
	}
	if(val<=k)
		{
			arr[count]=1;
			count++;
	    }
	else
		break;

	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	if(count!=0)
	cout<<start+1;
	else
		cout<<0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int arr[100000];
void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	int val=0,count=0;
	while(val<k)
	{
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				val=val+a[i]-b[i];
		}
	}
	if(flag)
		{
			arr[count]=1;
			count++;
	    }
			k=k-val;
			val=0;
	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int arr[100000];
void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	int val=0,count=0;
	while(val<=k)
	{
		k=k-val;
		val=0;
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				 val=val+a[i]-b[i];
		}
	}
	if(val<=k)
		{
			arr[count]=1;
			count++;
	    }
	else
		break;

	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int arr[100000];

void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a;
	vector<int>b;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
	}
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		b.push_back(x);
	}
	int val=0;
	int count=0;
	while(val<=k)
	{
		k=k-val;
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				val=val+a[i]-b[i];
		}
	}
	if(flag)
		{
			arr[count]=1;
			count++;
	    }
	}
	int start=0,end=100000000;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int arr[100000];
void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	int val=0,count=0;
	while(val<=k)
	{
		k=k-val;
		val=0;
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				 b[i]=0;
				 val=val+a[i]-b[i];
		}
	}
	if(val<=k)
		{
			arr[count]=1;
			count++;
	    }
	else
		break;

	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int arr[100000];
void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	int val=0,count=0;
	while(val<=k)
	{
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				val=val+a[i]-b[i];
		}
	}
	if(flag)
		{
			arr[count]=1;
			count++;
	    }
			k=k-val;
	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int arr[100000000];

void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a;
	vector<int>b;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
	}
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		b.push_back(x);
	}
	int val=0;
	int count=0;
	while(val<=k)
	{
		k=k-val;
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				val=val+a[i]-b[i];
		}
	}
	if(flag)
		{
			arr[count]=1;
			count++;
	    }
	}
	int start=0,end=100000000;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int arr[100000];
void main()
{
	memset(arr,0,sizeof arr);
	int n,k;
	cin>>n>>k;
	vector<int>a(n),b(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
	}
	int val=0,count=0;
	while(val<=k)
	{
		bool flag;
	for(int i=0;i<n;i++)
	{
		 flag=true;
		if(a[i]<=b[i])
			b[i]-=a[i];
		else
			{
				flag=false;
				 val=val+a[i]-b[i];
		}
	}
	k=k-val;
	if(k>=0)
		{
			arr[count]=1;
			count++;
	    }
			val=0;
	}
	int start=0,end=100000-1;
	while(start<end)
	{
	int mid=start+(end-start+1)/2;
	if(arr[mid]==1)
		start=mid;
	else
		end=mid-1;
	}
	cout<<start+1;
}


#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<math.h>
#include<cmath>
#include<iomanip>
#define ll long long
using namespace std;
long double pi = 3.14159265358979323846;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

ll n, p;
int need [100005];
int got[100005];

bool can(ll med) {
	ll w = p;
	ll sum = 0;
	for (int i = 0; i < n; i++)
	{
		if ((got[i] + w) / need[i] < med)
			return 0;
		else
			w -= max((ll) 0, med * need[i] - got[i]);
	}
	return 1;
}
	  int main() {
		  fast
			  cin >> n>>p;

		  for (int i = 0; i < n; i++)
			  cin >> need[i];
		  for (int i = 0; i < n; i++)
			  cin >> got[i];
		  ll r = 10e9, l = 0;
		  ll res = 0;
		  while (l <= r) {
			  ll med = (r + l)/2;
			  if (can(med)) {
				  res = med;
				  l = med + 1;
			  }
			  else
				  r = med - 1;
		  }
		  cout << res << endl;
		  return 0;
}


#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<math.h>
#include<cmath>
#include<iomanip>
#define ll long long
using namespace std;
long double pi = 3.14159265358979323846;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

ll n, p;
int* need = new int[n];
int* got = new int[n];

bool can(ll med) {
	ll w = p;
	ll sum = 0;
	for (int i = 0; i < n; i++)
	{
		if ((got[i] + w) / need[i] < med)
			return 0;
		else
			w -= max((ll) 0, med * need[i] - got[i]);
	}
	return 1;
}
	  int main() {
		  fast
			  cin >> n>>p;

		  for (int i = 0; i < n; i++)
			  cin >> need[i];
		  for (int i = 0; i < n; i++)
			  cin >> got[i];
		  ll r = 10e9, l = 0;
		  ll res = 0;
		  while (l <= r) {
			  ll med = (r + l)/2;
			  if (can(med)) {
				  res = med;
				  l = med + 1;
			  }
			  else
				  r = med - 1;
		  }
		  cout << res << endl;
		  return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

//#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
const int N = 100005;
int a[N],b[N];
set<II> s;
int main(){
	int n,k;
	si(n);si(k);
	for(int i=0;i<n;i++) si(a[i]);
	for(int i=0;i<n;i++) si(b[i]);
	int mn = INT_MAX;
	for(int i=0;i<n;i++) s.insert(MP(b[i]/a[i],i));
	while(k){
		int j = s.begin()->S;
		s.erase(s.begin());
		trace(j,b[j]/a[j]);
		int add = min(a[j] - b[j]%a[j],k);
		b[j] += add;
		k -= add;
		s.insert(MP(b[j]/a[j],j));
		trace(j,b[j]/a[j]);
		for(auto it=s.begin();it!=s.end();it++) trace(it->F,it->S);
	}
	for(int i=0;i<n;i++) mn = min(mn,b[i]/a[i]);
	cout<<mn<<endl;
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define sz(x)((int)(x).size())

const int MOD = int(1e9) + 7;
const int MAXN = int(1e5) + 10;

int add( int a, int b ) {
    if  ((a += b) >= MOD)
        a -= MOD;
    return a;
}

int dp[MAXN];
int sum[MAXN];
int n, m;
int s[MAXN];
int t[MAXN];
vector <int> who_end[MAXN];
vector <int> coord;

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &s[i], &t[i]);
        coord.push_back(s[i]);
        coord.push_back(t[i]);
    }

    sort(coord.begin(). coord.end());
    coord.resize(unique(coord.begin(), coord.end()) - coord.begin());

    for (int i = 0; i < m; i++) {
        s[i] = lower_bound(coord.begin(), coord.end(), s[i]) - coord.begin();
        t[i] = lower_bound(coord.begin(), coord.end(), t[i]) - coord.begin();
        who_end[t[i]].push_back(i);
    }

    sum[0] = 0;
    sum[1] = 1;
    dp[0] = 1;
    for (int i = 1; i < sz(coord); i++) {
        dp[i] = 0;
        for (int j = 0; j < sz(who_end[i]); j++) {
            int id = who_end[i][j];
            int l = s[id];
            dp[i] = add(dp[i], add(sum[i], -sum[l] + MOD));
        }
        sum[i + 1] = add(sum[i], dp[i]);
    }

    if  (*coord.rbegin() != n)
        dp[sz(coord)] = 0;

    printf("%d\n", dp[sz(coord)]);
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define sz(x)((int)(x).size())

const int MOD = int(1e9) + 7;
const int MAXN = int(1e5) + 10;

int add( int a, int b ) {
    if  ((a += b) >= MOD)
        a -= MOD;
    return a;
}

int dp[MAXN];
int sum[MAXN];
int n, m;
int s[MAXN];
int t[MAXN];
vector <int> who_end[MAXN];
vector <int> coord;

int main() {
    scanf("%d%d", &n, &m);

    if  (m == 0) {
        puts("0");
        return 0;
    }

    for (int i = 0; i < m; i++) {
        scanf("%d%d", &s[i], &t[i]);
        coord.push_back(s[i]);
        coord.push_back(t[i]);
    }

    sort(coord.begin(), coord.end());
    coord.resize(unique(coord.begin(), coord.end()) - coord.begin());

    for (int i = 0; i < m; i++) {
        s[i] = lower_bound(coord.begin(), coord.end(), s[i]) - coord.begin();
        t[i] = lower_bound(coord.begin(), coord.end(), t[i]) - coord.begin();
        who_end[t[i]].push_back(i);
    }

    sum[0] = 0;
    sum[1] = 1;
    dp[0] = 1;
    for (int i = 1; i < sz(coord); i++) {
        dp[i] = 0;
        for (int j = 0; j < sz(who_end[i]); j++) {
            int id = who_end[i][j];
            int l = s[id];
            dp[i] = add(dp[i], add(sum[i], -sum[l] + MOD));
        }
        sum[i + 1] = add(sum[i], dp[i]);
    }

    if  (*coord.rbegin() != n)
        dp[sz(coord) - 1] = 0;

    printf("%d\n", dp[sz(coord) - 1]);
    return 0;
}


#include <cstdio>
#include <vector>

using namespace std;

#define sz(x)((int)(x).size())

const int MOD = int(1e9) + 7;
const int MAXN = int(1e5) + 10;

int add( int a, int b ) {
    if  ((a += b) >= MOD)
        a -= MOD;
    return a;
}

int dp[MAXN];
int sum[MAXN];
int n, m;
int s[MAXN];
int t[MAXN];
vector <int> who_end[MAXN];
vector <int> coord;

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &s[i], &t[i]);
        coord.push_back(s[i]);
        coord.push_back(t[i]);
    }

    sort(coord.begin(). coord.end());
    coord.resize(unique(coord.begin(), coord.end()) - coord.begin());

    for (int i = 0; i < m; i++) {
        s[i] = lower_bound(coord.begin(), coord.end(), s[i]) - coord.begin();
        t[i] = lower_bound(coord.begin(), coord.end(), t[i]) - coord.begin();
        who_end[t[i]] = i;
    }

    sum[0] = 0;
    sum[1] = 1;
    dp[0] = 1;
    for (int i = 1; i < sz(coord); i++) {
        dp[i] = 0;
        for (int j = 0; j < sz(who_end[i]); j++) {
            int id = who_end[i][j];
            int l = s[id];
            dp[i] = add(dp[i], add(sum[i], -sum[l] + MOD));
        }
        sum[i + 1] = add(sum[i], dp[i]);
    }

    if  (*coord.rbegin() != n)
        dp[sz(coord)] = 0;

    printf("%d\n", dp[sz(coord)]);
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define sz(x)((int)(x).size())

const int MOD = int(1e9) + 7;
const int MAXN = int(1e5) + 10;

int add( int a, int b ) {
    if  ((a += b) >= MOD)
        a -= MOD;
    return a;
}

int dp[MAXN];
int sum[MAXN];
int n, m;
int s[MAXN];
int t[MAXN];
vector <int> who_end[MAXN];
vector <int> coord;

int main() {
    scanf("%d%d", &n, &m);

    if  (m == 0) {
        puts("0");
        return 0;
    }

    for (int i = 0; i < m; i++) {
        scanf("%d%d", &s[i], &t[i]);
        coord.push_back(s[i]);
        coord.push_back(t[i]);
    }

    sort(coord.begin(), coord.end());
    coord.resize(unique(coord.begin(), coord.end()) - coord.begin());

    for (int i = 0; i < m; i++) {
        s[i] = lower_bound(coord.begin(), coord.end(), s[i]) - coord.begin();
        t[i] = lower_bound(coord.begin(), coord.end(), t[i]) - coord.begin();
        who_end[t[i]].push_back(i);
    }

    sum[0] = 0;
    sum[1] = 1;
    dp[0] = 1;
    for (int i = 1; i < sz(coord); i++) {
        dp[i] = 0;
        for (int j = 0; j < sz(who_end[i]); j++) {
            int id = who_end[i][j];
            int l = s[id];
            dp[i] = add(dp[i], add(sum[i], -sum[l] + MOD));
        }
        sum[i + 1] = add(sum[i], dp[i]);
    }

    if  (*coord.rbegin() != n || coord[0] != 0)
        dp[sz(coord) - 1] = 0;

    printf("%d\n", dp[sz(coord) - 1]);
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define sz(x)((int)(x).size())

const int MOD = int(1e9) + 7;
const int MAXN = 2 * int(1e5) + 10;

int add( int a, int b ) {
    if  ((a += b) >= MOD)
        a -= MOD;
    return a;
}

int dp[MAXN];
int sum[MAXN];
int n, m;
int s[MAXN];
int t[MAXN];
vector <int> who_end[MAXN];
vector <int> coord;

int main() {
    scanf("%d%d", &n, &m);

    if  (m == 0) {
        puts("0");
        return 0;
    }

    for (int i = 0; i < m; i++) {
        scanf("%d%d", &s[i], &t[i]);
        coord.push_back(s[i]);
        coord.push_back(t[i]);
    }

    sort(coord.begin(), coord.end());
    coord.resize(unique(coord.begin(), coord.end()) - coord.begin());

    for (int i = 0; i < m; i++) {
        s[i] = lower_bound(coord.begin(), coord.end(), s[i]) - coord.begin();
        t[i] = lower_bound(coord.begin(), coord.end(), t[i]) - coord.begin();
        who_end[t[i]].push_back(i);
    }

    sum[0] = 0;
    sum[1] = 1;
    dp[0] = 1;
    for (int i = 1; i < sz(coord); i++) {
        dp[i] = 0;
        for (int j = 0; j < sz(who_end[i]); j++) {
            int id = who_end[i][j];
            int l = s[id];
            dp[i] = add(dp[i], add(sum[i], -sum[l] + MOD));
        }
        sum[i + 1] = add(sum[i], dp[i]);
    }

    if  (*coord.rbegin() != n || coord[0] != 0)
        dp[sz(coord) - 1] = 0;

    printf("%d\n", dp[sz(coord) - 1]);
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define sz(x)((int)(x).size())

const int MOD = int(1e9) + 7;
const int MAXN = int(1e5) + 10;

int add( int a, int b ) {
    if  ((a += b) >= MOD)
        a -= MOD;
    return a;
}

int dp[MAXN];
int sum[MAXN];
int n, m;
int s[MAXN];
int t[MAXN];
vector <int> who_end[MAXN];
vector <int> coord;

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &s[i], &t[i]);
        coord.push_back(s[i]);
        coord.push_back(t[i]);
    }

    sort(coord.begin(), coord.end());
    coord.resize(unique(coord.begin(), coord.end()) - coord.begin());

    for (int i = 0; i < m; i++) {
        s[i] = lower_bound(coord.begin(), coord.end(), s[i]) - coord.begin();
        t[i] = lower_bound(coord.begin(), coord.end(), t[i]) - coord.begin();
        who_end[t[i]].push_back(i);
    }

    sum[0] = 0;
    sum[1] = 1;
    dp[0] = 1;
    for (int i = 1; i < sz(coord); i++) {
        dp[i] = 0;
        for (int j = 0; j < sz(who_end[i]); j++) {
            int id = who_end[i][j];
            int l = s[id];
            dp[i] = add(dp[i], add(sum[i], -sum[l] + MOD));
        }
        sum[i + 1] = add(sum[i], dp[i]);
    }

    if  (*coord.rbegin() != n)
        dp[sz(coord)] = 0;

    printf("%d\n", dp[sz(coord)]);
    return 0;
}


#include <cstdio>
#include <vector>

using namespace std;

#define sz(x)((int)(x).size())

const int MOD = int(1e9) + 7;
const int MAXN = int(1e5) + 10;

int add( int a, int b ) {
    if  ((a += b) >= MOD)
        a -= MOD;
    return a;
}

int dp[MAXN];
int sum[MAXN];
int n, m;
int s[MAXN];
int t[MAXN];
vector <int> who_end[MAXN];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &s[i], &t[i]);
        who_end[t[i]].push_back(i);
    }

    sum[0] = 0;
    for (int i = 0; i <= n; i++) {
        dp[i] = 0;
        for (int j = 0; j < sz(who_end[i]); j++) {
            int id = who_end[i][j];
            int l = s[id];
            dp[i] = add(dp[i], add(sum[i], -sum[l] + MOD));
        }
        sum[i + 1] = add(sum[i], dp[i]);
    }

    printf("%d\n", dp[n]);
    return 0;
}


#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
     int n, m, i;
     int mod = 1000000007;
     vector<pair<int, int>> v;
     map<int, long long int> mp;
     map<int, long long int>::iterator it;

     mp[0]++;

     scanf("%d %d", &n, &m);

     for (i = 0; i < m; i++) {
	  int s, t;

	  scanf("%d %d", &s, &t);

	  v.push_back(make_pair(t, s));
     }

     sort(v.begin(), v.end());

     for (i = 0; i < v.size(); i++) {
	  int s = v[i].second;
	  int t = v[i].first;

	  for (it = mp.lower_bound(s); it != mp.end(); it++) {
	       if (it->first == t) continue;

	       mp[t] += it->second;
	       mp[t] %= mod;
	  }
     }

     printf("%d\n", (int)mp[n]);

     return 0;
}


#include <cstdio>
#include <map>
using namespace std;

int main()
{
     int n, m, i;
     int mod = 1000000007;
     map<int, long long int> mp;
     map<int, long long int>::iterator it;

     mp[0]++;

     scanf("%d %d", &n, &m);

     for (i = 0; i < m; i++) {
	  int s, t;

	  scanf("%d %d", &s, &t);

	  for (it = mp.lower_bound(s); it != mp.end(); it++) {
	       if (it->first == t) continue;

	       mp[t] += it->second;
	       mp[t] %= mod;
	  }
     }

     printf("%d\n", (int)mp[n]);

     return 0;
}


#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;

int main()
{
     int n, m, i;
     int mod = 1000000007;
     vector<pair<int, int>> v;
     map<int, long long int> mp;
     map<int, long long int>::iterator it;

     mp[0]++;

     scanf("%d %d", &n, &m);

     for (i = 0; i < m; i++) {
	  int s, t;

	  scanf("%d %d", &s, &t);

	  v.push_back(make_pair(t, s));
     }

     sort(v.begin(), v.end());

     for (i = 0; i < v.size(); i++) {
	  int s = v[i].second;
	  int t = v[i].first;

	  for (it = mp.lower_bound(s); it != mp.end(); it++) {
	       if (it->first == t) continue;

	       mp[t] += it->second;
	       mp[t] %= mod;
	  }
     }

     printf("%d\n", (int)mp[n]);

     return 0;
}


#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
using namespace std;

int main()
{
     int n, m, i;
     int mod = 1000000007;
     vector<pair<int, int> > v;
     map<int, long long int> mp;
     map<int, long long int>::iterator it;

     mp[0]++;

     scanf("%d %d", &n, &m);

     for (i = 0; i < m; i++) {
	  int s, t;

	  scanf("%d %d", &s, &t);

	  v.push_back(make_pair(t, s));
     }

     sort(v.begin(), v.end());

     for (i = 0; i < v.size(); i++) {
	  int s = v[i].second;
	  int t = v[i].first;

	  for (it = mp.lower_bound(s); it != mp.end(); it++) {
	       if (it->first == t) continue;

	       mp[t] += it->second;
	       mp[t] %= mod;
	  }
     }

     printf("%d\n", (int)mp[n]);

     return 0;
}


#include <iostream>
#include <map>
using namespace std;

int main()
{
     int n, m, i;
     int mod = 1000000007;
     map<int, long long int> mp;
     map<int, long long int>::iterator it;

     mp[0]++;

     scanf("%d %d", &n, &m);

     for (i = 0; i < m; i++) {
	  int s, t;

	  scanf("%d %d", &s, &t);

	  for (it = mp.lower_bound(s); it != mp.end(); it++) {
	       if (it->first == t) continue;

	       mp[t] += it->second;
	       mp[t] %= mod;
	  }
     }

     printf("%d\n", (int)mp[n]);

     return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

long long bit[100010];
int p = 1, mod = 1000000007;

long long sum(int i)
{
     long long s = 0;

     while (i > 0) {
	  s += bit[i];
	  s %= mod;

	  i -= i & -i;
     }

     return s;
}

void add(int i, long long x)
{
     if (i <= 0) return;

     while (i <= p) {
	  bit[i] += x;
	  bit[i] %= mod;

	  i += i & -i;
     }
}

int main()
{
     int n, m, i, j;
     vector <pair<int, int> > v;
     map <int, int> mp;
     map <int, int>::iterator it;

     scanf("%d %d", &n, &m);

     for (i = 0; i < m; i++) {
	  int s, t;

	  scanf("%d %d", &s, &t);

	  v.push_back(make_pair(t, s));

	  mp[t] = 1;
     }

     mp[0] = 1;

     for (it = mp.begin(); it != mp.end(); it++) {
	  it->second = p++;
     }

     p--;

     sort(v.begin(), v.end());

     add(1, 1);

     for (i = 0; i < v.size(); i++) {
	  it = mp.lower_bound(v[i].second);

	  add(mp[v[i].first], (sum(mp[v[i].first] - 1) - sum(it->second - 1) + mod) % mod);
     }

     if (mp[n] == 0) {
	  puts("0");
     } else {
	  printf("%I64d\n", (sum(mp[n]) - sum(mp[n] - 1) + mod) % mod);
     }

     return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
const int MAXN = 1e5 + 10;

struct edge
{
    int l, r, uk;
};

edge a[MAXN];
int dp[4 * MAXN];
int b[MAXN];
int n, m;

void update(int k)
{
    dp[k] = dp[k * 2] + dp[k * 2 + 1];
    if (k > 1)
        update(k / 2);
}
long long getsum(int v, int ll, int rr, int l, int r)
{
    if (ll > r || rr < l)
        return 0;
    if (ll >= l && rr <= r)
        return dp[v];
    return getsum(v * 2, ll, (ll + rr) / 2, l, r) + getsum(v * 2 + 1, (ll + rr) / 2 + 1, rr, l, r);
}
bool operator < (edge a, edge b)
{
    return a.r < b.r;
}
int binr (int l, int r, int q)
{
    while (l < r - 1)
    {
        if (b[(l + r) / 2] < q)
            l = (l + r) / 2;
        else
            r = (l + r) / 2;
    }
    return r;
}

int main()
{
    int i, size = 1, uk, l;
    cin >> n >> m;
    while (size < n + 1)
    {
        size *= 2;
    }
    for (i = 0; i < m; i++)
    {
        cin >> a[i].l >> a[i].r;
    }
    sort(a, a + m);
    b[0] = 0;
    b[1] = a[0].r;
    uk = 2;
    for (i = 1; i < m; i++)
    {
        if (a[i - 1].r != a[i].r)
        {
            b[uk] = a[i].r;
            uk++;
        }
        a[i].uk = uk;
    }
    dp[size] = 1;
    update(size / 2);
    for (i = 0; i < m; i++)
    {
        l = binr(-1, uk - 1, a[i].l);
        l++;
        dp[size + i + 1] += getsum(1, 1, size, l, i + 1);
        update((size + i) / 2);
    }
    uk--;
    if (a[m - 1].r != n)
        cout << 0;
    else
        cout << dp[size + uk];

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
const int MAXN = 1e5 + 10;
const int p = 1e9 + 7;

struct edge
{
    int l, r, uk;
};

edge a[MAXN];
int dp[4 * MAXN];
int b[MAXN];
int n, m;

void update(int k)
{
    dp[k] = (dp[k * 2] + dp[k * 2 + 1]) % p;
    if (k > 1)
        update(k / 2);
}
long long getsum(int v, int ll, int rr, int l, int r)
{
    if (ll > r || rr < l)
        return 0;
    if (ll >= l && rr <= r)
        return dp[v];
    return (getsum(v * 2, ll, (ll + rr) / 2, l, r) + getsum(v * 2 + 1, (ll + rr) / 2 + 1, rr, l, r)) % p;
}
bool operator < (edge a, edge b)
{
    return a.r < b.r;
}
int binr (int l, int r, int q)
{
    while (l < r - 1)
    {
        if (b[(l + r) / 2] < q)
            l = (l + r) / 2;
        else
            r = (l + r) / 2;
    }
    return r;
}

int main()
{
   int i, size = 1, uk, l;
    cin >> n >> m;
    while (size < n + 1)
    {
        size *= 2;
    }
    for (i = 0; i < m; i++)
    {
        cin >> a[i].l >> a[i].r;
    }
    sort(a, a + m);
    b[0] = 0;
    b[1] = a[0].r;
    uk = 2;
    for (i = 1; i < m; i++)
    {
        if (a[i - 1].r != a[i].r)
        {
            b[uk] = a[i].r;
            uk++;
        }
        a[i].uk = uk;
    }
    dp[size] = 1;
    update(size / 2);
    int uk1 = 1;
    for (i = 0; i < m; i++)
    {
        l = binr(-1, uk - 1, a[i].l);
        l++;
        if (i != 0 && a[i - 1].r != a[i].r)
            uk1++;
        dp[size + uk1] = (dp[size + uk1] + getsum(1, 1, size, l, i + 1)) % p;
        update((size + i) / 2);
    }
    uk--;
    if (a[m - 1].r != n)
        cout << 0;
    else
        cout << dp[size + m];

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
const int MAXN = 1e5 + 10;
const int p = 1e9 + 7;

struct edge
{
    int l, r, uk;
};

edge a[MAXN];
int dp[4 * MAXN];
int b[MAXN];
int n, m;

void update(int k)
{
    dp[k] = (dp[k * 2] + dp[k * 2 + 1]) % p;
    if (k > 1)
        update(k / 2);
}
long long getsum(int v, int ll, int rr, int l, int r)
{
    if (ll > r || rr < l)
        return 0;
    if (ll >= l && rr <= r)
        return dp[v];
    return (getsum(v * 2, ll, (ll + rr) / 2, l, r) + getsum(v * 2 + 1, (ll + rr) / 2 + 1, rr, l, r)) % p;
}
bool operator < (edge a, edge b)
{
    return a.r < b.r;
}
int binr (int l, int r, int q)
{
    while (l < r - 1)
    {
        if (b[(l + r) / 2] < q)
            l = (l + r) / 2;
        else
            r = (l + r) / 2;
    }
    return r;
}

int main()
{
    int i, size = 1, uk, l;
    cin >> n >> m;
    while (size < m)
    {
        size *= 2;
    }
    for (i = 0; i < m; i++)
    {
        cin >> a[i].l >> a[i].r;
    }
    sort(a, a + m);
    b[0] = 0;
    b[1] = a[0].r;
    uk = 2;
    for (i = 1; i < m; i++)
    {
        if (a[i - 1].r != a[i].r)
        {
            b[uk] = a[i].r;
            uk++;
        }
        a[i].uk = uk;
    }
    dp[size] = 1;
    update(size / 2);
    int uk1 = 1;
    for (i = 0; i < m; i++)
    {
        l = binr(-1, uk - 1, a[i].l);
        l++;
        if (i != 0 && a[i - 1].r != a[i].r)
            uk1++;
        dp[size + uk1] = (dp[size + uk1] + getsum(1, 1, size, l, uk1)) % p;
        update((size + uk1) / 2);
    }
    uk--;
    if (a[m - 1].r != n)
        cout << 0;
    else
        cout << dp[size + uk1];

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
const int MAXN = 1e5 + 10;
const int p = 1e9 + 7;

struct edge
{
    int l, r, uk;
};

edge a[MAXN];
int dp[4 * MAXN];
int b[MAXN];
int n, m;

void update(int k)
{
    dp[k] = (dp[k * 2] + dp[k * 2 + 1]) % p;
    if (k > 1)
        update(k / 2);
}
long long getsum(int v, int ll, int rr, int l, int r)
{
    if (ll > r || rr < l)
        return 0;
    if (ll >= l && rr <= r)
        return dp[v];
    return (getsum(v * 2, ll, (ll + rr) / 2, l, r) + getsum(v * 2 + 1, (ll + rr) / 2 + 1, rr, l, r)) % p;
}
bool operator < (edge a, edge b)
{
    return a.r < b.r;
}
int binr (int l, int r, int q)
{
    while (l < r - 1)
    {
        if (b[(l + r) / 2] < q)
            l = (l + r) / 2;
        else
            r = (l + r) / 2;
    }
    return r;
}

int main()
{
    int i, size = 1, uk, l;
    cin >> n >> m;
    while (size < n + 1)
    {
        size *= 2;
    }
    for (i = 0; i < m; i++)
    {
        cin >> a[i].l >> a[i].r;
    }
    sort(a, a + m);
    b[0] = 0;
    b[1] = a[0].r;
    uk = 2;
    for (i = 1; i < m; i++)
    {
        if (a[i - 1].r != a[i].r)
        {
            b[uk] = a[i].r;
            uk++;
        }
        a[i].uk = uk;
    }
    dp[size] = 1;
    update(size / 2);
    int uk1 = 1;
    for (i = 0; i < m; i++)
    {
        l = binr(-1, uk - 1, a[i].l);
        l++;
        if (i != 0 && a[i - 1].r != a[i].r)
            uk1++;
        dp[size + uk1] = (dp[size + uk1] + getsum(1, 1, size, l, uk1)) % p;
        update((size + uk1) / 2);
    }
    uk--;
    if (a[m - 1].r != n)
        cout << 0;
    else
        cout << dp[size + uk1];

    return 0;
}


#define DBG 1

#include <cstring>
#include <map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

#define MD 1000000007

ll md(ll a) {
    a %= MD;
    return (a < 0 ? MD : 0) + a;
}

struct n_ {
    int p;
    ll v;
    ll s;
};

struct p_ {
    int s;
    int t;
};

vector<n_> v;
p_ p[100004];

bool cmp(p_ a, p_ b) {
    return a.t < b.t;
}

int main() {
    n_ a = {0, 1, 0};
    v.push_back(a);

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++)
        cin >> p[i].s >> p[i].t;

    sort(p, p+m, cmp);

    for (int i = 0; i < m; i++) {
        int found = 0, r, l = v.size(), m, f;
        if (v[l-1].p != p[i].t) {
            n_ x = {p[i].t, 0, md(v[l-1].v + v[l-1].s)};
            v.push_back(x);
        }
        l = 0; r = v.size()-2; f = p[i].s;
        while (l <= r) {
            m = (l+r)/2;
            if (v[m].p == f || (v[m].p > f && v[m-1].p < f)) {
                found = 1;
                break;
            }
            if (v[m].p < f)
                l = m+1;
            else
                r = m-1;
        }
        if (found) {
            l = v.size();
            v[l-1].v += md(v[l-1].s - v[m].s);
        }
    }

    int l = v.size();
    if (v[l-1].p == n)
        cout << v[l-1].v << endl;
    else
        cout << "0\n";

    return 0;
}


#define DBG 1

#include <cstring>
#include <map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

#define MD 1000000007

ll md(ll a) {
    a %= MD;
    return (a < 0 ? MD : 0) + a;
}

struct n_ {
    int p;
    ll v;
    ll s;
};

struct p_ {
    int s;
    int t;
};

vector<n_> v;
p_ p[100004];

bool cmp(p_ a, p_ b) {
    return a.t < b.t;
}

int main() {
    n_ a = {0, 1, 0};
    v.push_back(a);

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++)
        cin >> p[i].s >> p[i].t;

    sort(p, p+m, cmp);

    for (int i = 0; i < m; i++) {
        int found = 0, r, l = v.size(), m, f;
        if (v[l-1].p != p[i].t) {
            n_ x = {p[i].t, 0, md(v[l-1].v + v[l-1].s)};
            v.push_back(x);
        }
        l = 0; r = v.size()-2; f = p[i].s;
        while (l <= r) {
            m = (l+r)/2;
            if (v[m].p == f || (v[m].p > f && v[m-1].p < f)) {
                found = 1;
                break;
            }
            if (v[m].p < f)
                l = m+1;
            else
                r = m-1;
        }
        if (found) {
            l = v.size();
            v[l-1].v += md(v[l-1].s - v[m].s);
            v[l-1].v = md(v[l-1].v);
        }
    }

    int l = v.size();
    if (v[l-1].p == n)
        cout << v[l-1].v << endl;
    else
        cout << "0\n";

    return 0;
}


#define DBG 1

#include <cstring>
#include <map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

#define MD 1000000007

ll md(ll a) {
    a %= MD;
    return (a < 0 ? MD : 0) + a;
}

struct n_ {
    int p;
    ll v;
    ll s;
};

struct p_ {
    int s;
    int t;
};

vector<n_> v;
p_ p[100004];

bool cmp(p_ a, p_ b) {
    return a.t < b.t;
}

int main() {
    n_ a = {0, 1, 0};
    v.push_back(a);

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++)
        cin >> p[i].s >> p[i].t;

    sort(p, p+m, cmp);

    for (int i = 0; i < m; i++) {
        int r, l = v.size(), m, f;
        if (v[l-1].p != p[i].t) {
            n_ x = {p[i].t, 0, md(v[l-1].v + v[l-1].s)};
            v.push_back(x);
        }
        l = 0; r = v.size()-2; f = p[i].s;
        while (1) {
            m = (l+r)/2;
            if (v[m].p == f || (v[m].p > f && v[m-1].p < f))
                break;
            if (v[m].p < f)
                l = m+1;
            else
                r = m-1;
        }
        l = v.size();
        v[l-1].v += md(v[l-1].s - v[m].s);
    }

    int l = v.size();
    if (v[v.size()-1].p == n)
        cout << v[v.size()-1].v << endl;
    else
        cout << "0\n";

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int const INF = (1<<30);
int const MAXN = (int)1e5+100;
int const mod = 1e9 + 7;
int d[MAXN], c[200002],size,s[MAXN],t[MAXN];
vector <int> e[MAXN];
int n,m,sum[MAXN];

int main (){
	//freopen ("input.txt","r",stdin);
	//freopen ("output.txt","w",stdout);
	cin >>n>>m;
	c[size++] = 0;
	c[size++] = n;
	for (int i=1;i<=m;i++){
		int x,y;
		cin >>x>>y;
		s[i] = x;
		t[i] = y;
		c[size++] = x;
		c[size++] = y;
	}
 	sort (c,c+size);
 	size = unique (c,c+size) - c;
 	for (int i=0;i<size;i++){
 		int a = lower_bound(c,c+size,s[i]) - c;
 		int b = lower_bound(c,c+size,t[i]) - c;
		e[b].pb(a);
 	}
 	d[0] = 1;
 	sum[1] = 1;
 	for (int i=1;i<size;i++){
 		for (int j=0;j<e[i].size();j++){
 			d[i] = (d[i] + sum[i] - sum[e[i][j]] + mod)%mod;
 		}
 		sum[i+1] = sum[i] + d[i];
 	}
 	cout <<d[size-1];

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int const INF = (1<<30);
int const MAXN = (int)1e5+100;
int const mod = 1e9 + 7;
int d[MAXN], c[200002],size,s[MAXN],t[MAXN];
vector <int> e[MAXN];
int n,m,sum[MAXN];

int main (){
	//freopen ("input.txt","r",stdin);
	//freopen ("output.txt","w",stdout);
	cin >>n>>m;
	c[size++] = 0;
	c[size++] = n;
	for (int i=1;i<=m;i++){
		int x,y;
		cin >>x>>y;
		s[i] = x;
		t[i] = y;
		c[size++] = x;
		c[size++] = y;
	}
 	sort (c,c+size);
 	size = unique (c,c+size) - c;
 	for (int i=1;i<=m;i++){
 		int a = lower_bound(c,c+size,s[i]) - c;
 		int b = lower_bound(c,c+size,t[i]) - c;
		e[b].pb(a);
 	}
 	d[0] = 1;
 	sum[1] = 1;
 	for (int i=1;i<size;i++){
 		for (int j=0;j<e[i].size();j++){
 			d[i] = (d[i] + sum[i] - sum[e[i][j]] + mod)%mod;
 		}
 		sum[i+1] = sum[i] + d[i];
 	}
 	cout <<d[size-1];

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int const INF = (1<<30);
int const MAXN = (int)1e5+100;
int const mod = 1e9 + 7;
ll d[MAXN], c[300004],size,s[MAXN],t[MAXN];
vector <ll> e[MAXN*2];
ll n,m,sum[MAXN*2];

int main (){
	//freopen ("input.txt","r",stdin);
	//freopen ("output.txt","w",stdout);
	cin >>n>>m;
	c[size++] = 0;
	c[size++] = n;
	for (int i=1;i<=m;i++){
		int x,y;
		cin >>x>>y;
		s[i] = x;
		t[i] = y;
		c[size++] = x;
		c[size++] = y;
	}
 	sort (c,c+size);
 	size = unique (c,c+size) - c;
 	for (int i=1;i<=m;i++){
 		int a = lower_bound(c,c+size,s[i]) - c;
 		int b = lower_bound(c,c+size,t[i]) - c;
		e[b].pb(a);
 	}
 	d[0] = 1;
 	sum[1] = 1;
 	for (int i=1;i<size;i++){
 		for (int j=0;j<e[i].size();j++){
 			d[i] = (d[i] + sum[i] - sum[e[i][j]] + mod)%mod;
 		}
 		sum[i+1] = (sum[i] + d[i])%mod;
 	}
 	cout <<d[size-1];

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int const INF = (1<<30);
int const MAXN = (int)1e5+100;
int const mod = 1e9 + 7;
int d[MAXN], c[300004],size,s[MAXN],t[MAXN];
vector <int> e[MAXN*2];
int n,m,sum[MAXN*2];

int main (){
	//freopen ("input.txt","r",stdin);
	//freopen ("output.txt","w",stdout);
	cin >>n>>m;
	c[size++] = 0;
	c[size++] = n;
	for (int i=1;i<=m;i++){
		int x,y;
		cin >>x>>y;
		s[i] = x;
		t[i] = y;
		c[size++] = x;
		c[size++] = y;
	}
 	sort (c,c+size);
 	size = unique (c,c+size) - c;
 	for (int i=1;i<=m;i++){
 		int a = lower_bound(c,c+size,s[i]) - c;
 		int b = lower_bound(c,c+size,t[i]) - c;
		e[b].pb(a);
 	}
 	d[0] = 1;
 	sum[1] = 1;
 	for (int i=1;i<size;i++){
 		for (int j=0;j<e[i].size();j++){
 			d[i] = (d[i] + sum[i] - sum[e[i][j]] + mod)%mod;
 		}
 		sum[i+1] = (sum[i] + d[i])%mod;
 	}
 	cout <<d[size-1];

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int const INF = (1<<30);
int const MAXN = (int)1e5+100;
int const mod = 1e9 + 7;
int d[MAXN], c[200002],size,s[MAXN],t[MAXN];
vector <int> e[MAXN];
int n,m,sum[MAXN];

int main (){
	//freopen ("input.txt","r",stdin);
	//freopen ("output.txt","w",stdout);
	cin >>n>>m;
	c[size++] = 0;
	c[size++] = n;
	for (int i=1;i<=m;i++){
		int x,y;
		cin >>x>>y;
		s[i] = x;
		t[i] = y;
		c[size++] = x;
		c[size++] = y;
	}
 	sort (c,c+size);
 	size = unique (c,c+size) - c;
 	for (int i=1;i<=m;i++){
 		int a = lower_bound(c,c+size,s[i]) - c;
 		int b = lower_bound(c,c+size,t[i]) - c;
		e[b].pb(a);
 	}
 	d[0] = 1;
 	sum[1] = 1;
 	for (int i=1;i<size;i++){
 		for (int j=0;j<e[i].size();j++){
 			d[i] = (d[i] + sum[i] - sum[e[i][j]] + mod)%mod;
 		}
 		sum[i+1] = (sum[i] + d[i] + mod)%mod;
 	}
 	cout <<d[size-1];

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int const INF = (1<<30);
int const MAXN = (int)1e5+100;
int const mod = 1e9 + 7;
ll d[2*MAXN], c[300004],size,s[MAXN],t[MAXN];
vector <ll> e[MAXN*2];
ll n,m,sum[MAXN*2];

int main (){
	//freopen ("input.txt","r",stdin);
	//freopen ("output.txt","w",stdout);
	cin >>n>>m;
	c[size++] = 0;
	c[size++] = n;
	for (int i=1;i<=m;i++){
		int x,y;
		cin >>x>>y;
		s[i] = x;
		t[i] = y;
		c[size++] = x;
		c[size++] = y;
	}
 	sort (c,c+size);
 	size = unique (c,c+size) - c;
 	for (int i=1;i<=m;i++){
 		int a = lower_bound(c,c+size,s[i]) - c;
 		int b = lower_bound(c,c+size,t[i]) - c;
		e[b].pb(a);
 	}
 	d[0] = 1;
 	sum[1] = 1;
 	for (int i=1;i<size;i++){
 		for (int j=0;j<e[i].size();j++){
 			d[i] = (d[i] + sum[i] - sum[e[i][j]] + mod)%mod;
 		}
 		sum[i+1] = (sum[i] + d[i])%mod;
 	}
 	cout <<d[size-1];

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <cmath>

using namespace std;

#define N 100010
#define M 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-8
#define LL long long
#define Pi acos(-1)

struct Node{
    int s,t;
    bool operator < (const Node tmp) const{
        return t < tmp.t;
    }
}a[N];

int n, m;

int find(int l, int r, int x){
    if (l > r) return -1;
    if (a[r].t < x) return -1;
    int mid;
    while (l < r){
        mid = (l + r) >> 1;
        if (x <= a[mid].t){
            r = mid;
        }
        else {
            l = mid + 1;
        }
    }
    if (l > 1) l--;
    while (a[l].t < x && l < m) l++;
    l--;
    return l;
}

int main(){
    //freopen("a.txt","r",stdin);
    int n, i, pos, res, sum[N], dp[N];
	while (scanf("%d%d",&n,&m) != EOF){
        for (i = 1; i <= m; ++i){
            scanf("%d%d",&a[i].s, &a[i].t);
        }
        sort(a + 1, a + m + 1);
        sum[0] = 0;
        res = 0;
        //memset(dp, 0, sizeof(dp));
        for (i = 1; i <= m; ++i){
            pos = find(1, i - 1, a[i].s);
            if (pos != -1){
                dp[i] = (sum[i - 1] - sum[pos] + M) % M;
            }
            else dp[i] = 0;
            if (a[i].s == 0) dp[i]++;
            sum[i] = (sum[i - 1] + dp[i]) % M;
            if (a[i].t == n){
                res = (res + dp[i]) % M;
            }
        }
        printf("%d\n", res);
	}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <cmath>

using namespace std;

#define N 100010
#define M 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-8
#define LL long long
#define Pi acos(-1)

struct Node{
    int s,t;
    bool operator < (const Node tmp) const{
        return t < tmp.t;
    }
}a[N];

int n, m;

int find(int l, int r, int x){
    if (l > r) return -1;
    if (a[r].t < x) return -1;
    int m;
    while (l < r){
        m = (l + r) >> 1;
        if (x <= a[m].t){
            r = m;
        }
        else {
            l = m + 1;
        }
    }
    if (l > 1) l--;
    while (a[l].t < x && l < m) l++;
    l--;
    return l;
}

int main(){
    int n, i, pos, res, sum[N], dp[N];
	while (scanf("%d%d",&n,&m) != EOF){
        for (i = 1; i <= m; ++i){
            scanf("%d%d",&a[i].s, &a[i].t);
        }
        sort(a + 1, a + m + 1);
        sum[0] = 0;
        res = 0;
        for (i = 1; i <= m; ++i){
            pos = find(1, i - 1, a[i].s);
            dp[i] = (sum[i - 1] - sum[pos] + M) % M;
            if (a[i].s == 0) dp[i]++;
            sum[i] = (sum[i - 1] + dp[i]) % M;
            if (a[i].t == n){
                res = (res + dp[i]) % M;
            }
        }
        printf("%d\n", res);
	}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <cmath>

using namespace std;

#define N 100010
#define M 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-8
#define LL long long
#define Pi acos(-1)

struct Node{
    int s,t;
    bool operator < (const Node tmp) const{
        return t < tmp.t;
    }
}a[N];

int n, m;

int find(int l, int r, int x){
    if (l > r) return -1;
    if (a[r].t < x) return -1;
    int mid;
    while (l < r){
        mid = (l + r) >> 1;
        if (x <= a[mid].t){
            r = mid;
        }
        else {
            l = mid + 1;
        }
    }
    if (l > 1) l--;
    while (a[l].t < x && l <= r) l++;
    l--;
    return l;
}

int main(){
    //freopen("a.txt","r",stdin);
    int n, i, pos, res, sum[N], dp[N], flag[N];
	while (scanf("%d%d",&n,&m) != EOF){
        for (i = 1; i <= m; ++i){
            scanf("%d%d",&a[i].s, &a[i].t);
        }
        sort(a + 1, a + m + 1);
        sum[0] = 0;
        res = 0;
        flag[1] = 0;
        for (i = 2; i <= m; ++i){
            if (a[i].t == a[i - 1].t) flag[i] = flag[i - 1];
            else flag[i] = i - 1;
        }
        //memset(dp, 0, sizeof(dp));
        for (i = 1; i <= m; ++i){
            pos = find(1, flag[i], a[i].s);
            if (pos != -1){
                dp[i] = (sum[i - 1] - sum[pos] + M) % M;
            }
            else dp[i] = 0;
            if (a[i].s == 0) dp[i] = (dp[i] + 1) % M;
            sum[i] = (sum[i - 1] + dp[i]) % M;
            if (a[i].t == n){
                res = (res + dp[i]) % M;
            }
        }
        printf("%d\n", res);
	}
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <cmath>

using namespace std;

#define N 100010
#define M 1000000007
#define inf 0x3f3f3f3f
#define eps 1e-8
#define LL long long
#define Pi acos(-1)

struct Node{
    int s,t;
    bool operator < (const Node tmp) const{
        return t < tmp.t;
    }
}a[N];

int n, m;

int find(int l, int r, int x){
    if (l > r) return -1;
    if (a[r].t < x) return -1;
    int mid;
    while (l < r){
        mid = (l + r) >> 1;
        if (x <= a[mid].t){
            r = mid;
        }
        else {
            l = mid + 1;
        }
    }
    if (l > 1) l--;
    while (a[l].t < x && l <= r) l++;
    l--;
    return l;
}

int main(){
    //freopen("a.txt","r",stdin);
    int n, i, pos, res, sum[N], dp[N], flag[N];
	while (scanf("%d%d",&n,&m) != EOF){
        for (i = 1; i <= m; ++i){
            scanf("%d%d",&a[i].s, &a[i].t);
        }
        sort(a + 1, a + m + 1);
        sum[0] = 0;
        res = 0;
        flag[1] = 0;
        for (i = 2; i <= m; ++i){
            if (a[i].t == a[i - 1].t) flag[i] = flag[i - 1];
            else flag[i] = i - 1;
        }
        //memset(dp, 0, sizeof(dp));
        for (i = 1; i <= m; ++i){
            pos = find(1, flag[i], a[i].s);
            if (pos != -1){
                dp[i] = (sum[flag[i]] - sum[pos] + M) % M;
            }
            else dp[i] = 0;
            if (a[i].s == 0) dp[i] = (dp[i] + 1) % M;
            sum[i] = (sum[i - 1] + dp[i]) % M;
            if (a[i].t == n){
                res = (res + dp[i]) % M;
            }
        }
        printf("%d\n", res);
	}
    return 0;
}


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

#define mp make_pair

typedef pair<int,int> PII;
const int MOD = (int)1e9+7;
const int N = 201000;

struct San {
        int a[N],n;
        void init() { n = 0; }
        void push(int x){ a[n++] = x; }
        void doit() {
                sort(a,a+n);
                n = unique(a,a+n)-a;
        }
        int operator [] (int x) {
                return lower_bound(a,a+n,x)-a;
        }
}ss;
int n,m,C[N];
PII bus[N];

inline void add(int &a,int b) { a += b; if (a>=MOD) a -= MOD; }

void treeAdd(int p,int dt) {
        for (int i = p; i < ss.n; i += i&-i) add(C[i],dt);
}
int treeSum(int p) {
        int ret = 0;
        for (int i = p; i > 0; i -= i&-i) add(ret,C[i]);
        return ret;
}

int main() {
        scanf("%d%d",&n,&m);
        ss.init();
        ss.push(-1);
        ss.push(0);
        ss.push(n);
        for (int i = 0; i < m; i ++) {
                scanf("%d%d",&bus[i].second,&bus[i].first);
                ss.push(bus[i].first);
                ss.push(bus[i].second);
        }
        ss.doit();
        treeAdd(1,1);
        sort(bus,bus+m);
        for (int i = 0; i < m; i ++) {
                int l = ss[bus[i].second];
                int r = ss[bus[i].first];
                int dt = 0;
                add(dt,treeSum(r-1));
                add(dt,MOD-treeSum(l-1));
                treeAdd(r,dt);
        }
        int ans = treeSum(ss[n]);
        add(ans,MOD-treeSum(ss[n]-1));
        printf("%d\n",ans);
        return 0;
}


#include <map>
#include <set>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <ctime>
#include <cfloat>
#include <vector>
#include <string>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3FFFFFFFFFLL

#define FILL(X, V) memset( X, V, sizeof(X) )
#define TI(X) __typeof((X).begin())
#define ALL(V) V.begin(), V.end()
#define SIZE(V) int((V).size())

#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define RFOR(i, b, a) for(int i = b; i >= a; --i)
#define REP(i, N) for(int i = 0; i < N; ++i)
#define RREP(i, N) for(int i = N-1; i >= 0; --i)
#define FORIT(i, a) for( TI(a) i = a.begin(); i != a.end(); i++ )

#define PB push_back
#define MP make_pair

template<typename T> T inline SQR( const T &a ){ return a*a; }
template<typename T> T inline ABS( const T &a ){ return a < 0 ? -a : a; }
template<typename T> T inline MIN( const T& a, const T& b){ if( a < b ) return a; return b; }
template<typename T> T inline MAX( const T& a, const T& b){ if( a > b ) return a; return b; }

const double EPS = 1e-9;
inline int SGN( double a ){ return a > EPS ? 1 : (a < -EPS ? -1 : 0); }
inline int CMP( double a, double b ){ return SGN(a - b); }

typedef long long int64;
typedef unsigned long long uint64;

using namespace std;

#define MAXM 100100

int N, M;

struct bus_t{
	int s, t;
	bus_t( int ss = 0, int tt = 0 ) : s(ss), t(tt) {}
	bool operator < ( const bus_t& b ) const {
		if( t != b.t ) return t < b.t;
		return s < b.s;
	}
};

bus_t bus[MAXM];

const int64 MOD = 1000000007LL;

int bit[2*MAXM + 1];
void up( int x, int tt ){
	while( x <= (2*MAXM) ){
		bit[x] = bit[x] + tt;
		bit[x] %= MOD;
		x += ( x & -x );
	}
}

int get( int x ){
	int ans = 0;
	while( x > 0 ){
		ans += bit[x];
		ans %= MOD;
		x -= ( x & -x );
	}
	return ans;
}

int main( int argc, char* argv[] ){

	ios::sync_with_stdio( false );

	cin >> N >> M;

	map< int, int > occ;
	REP( i, M ){
		cin >> bus[i].s >> bus[i].t;
		occ[ bus[i].s ]++;
		occ[ bus[i].t ]++;
	}
	occ[ 0 ]++;

	sort( bus, bus+M );
	occ[ N ]++;

	map< int, int > id;
	int cid = 1;
	FORIT( x, occ ) id[ x->first ] = cid++;

	up( 1, 1 );
	REP( i, M ){
		up( id[ bus[i].t ], ( get( id[ bus[i].t ] ) - get( id[ bus[i].s ]-1 ) + MOD ) % MOD );
	}

	cout << ( get( id[N] ) - get( id[N] - 1 ) + MOD ) % MOD << "\n";

	return 0;
}


#include <map>
#include <set>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <ctime>
#include <cfloat>
#include <vector>
#include <string>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3FFFFFFFFFLL

#define FILL(X, V) memset( X, V, sizeof(X) )
#define TI(X) __typeof((X).begin())
#define ALL(V) V.begin(), V.end()
#define SIZE(V) int((V).size())

#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define RFOR(i, b, a) for(int i = b; i >= a; --i)
#define REP(i, N) for(int i = 0; i < N; ++i)
#define RREP(i, N) for(int i = N-1; i >= 0; --i)
#define FORIT(i, a) for( TI(a) i = a.begin(); i != a.end(); i++ )

#define PB push_back
#define MP make_pair

template<typename T> T inline SQR( const T &a ){ return a*a; }
template<typename T> T inline ABS( const T &a ){ return a < 0 ? -a : a; }
template<typename T> T inline MIN( const T& a, const T& b){ if( a < b ) return a; return b; }
template<typename T> T inline MAX( const T& a, const T& b){ if( a > b ) return a; return b; }

const double EPS = 1e-9;
inline int SGN( double a ){ return a > EPS ? 1 : (a < -EPS ? -1 : 0); }
inline int CMP( double a, double b ){ return SGN(a - b); }

typedef long long int64;
typedef unsigned long long uint64;

using namespace std;

#define MAXM 100100

int N, M;

struct bus_t{
	int s, t;
	bus_t( int ss = 0, int tt = 0 ) : s(ss), t(tt) {}
	bool operator < ( const bus_t& b ) const {
		if( t != b.t ) return t < b.t;
		return s < b.s;
	}
};

bus_t bus[MAXM];

const int64 MOD = 1000000007LL;

int64 bit[2*MAXM + 1];

void up( int x, int64 tt ){
	while( x <= (2*MAXM) ){
		bit[x] = bit[x] + tt;
		bit[x] %= MOD;
		x += ( x & -x );
	}
}

int64 get( int x ){
	int64 ans = 0;
	while( x > 0 ){
		ans += bit[x];
		ans %= MOD;
		x -= ( x & -x );
	}
	return ans;
}

int main( int argc, char* argv[] ){

	ios::sync_with_stdio( false );

	cin >> N >> M;

	map< int, int > occ;
	REP( i, M ){
		cin >> bus[i].s >> bus[i].t;
		occ[ bus[i].s ]++;
		occ[ bus[i].t ]++;
	}
	occ[ 0 ]++;
	occ[ N ]++;

	sort( bus, bus+M );

	map< int, int > id;
	int cid = 1;
	FORIT( x, occ ) id[ x->first ] = cid++;

	up( 1, 1 );
	REP( i, M ){
		up( id[ bus[i].t ], ( get( id[ bus[i].t ]-1 ) - get( id[ bus[i].s ]-1 ) + MOD ) % MOD );
	}

	cout << ( get( id[N] ) - get( id[N] - 1 ) + MOD ) % MOD << "\n";

	return 0;
}


#include <map>
#include <set>
#include <list>
#include <stack>
#include <cmath>
#include <queue>
#include <ctime>
#include <cfloat>
#include <vector>
#include <string>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>

#define INF 0x3F3F3F3F
#define LINF 0x3F3F3F3FFFFFFFFFLL

#define FILL(X, V) memset( X, V, sizeof(X) )
#define TI(X) __typeof((X).begin())
#define ALL(V) V.begin(), V.end()
#define SIZE(V) int((V).size())

#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define RFOR(i, b, a) for(int i = b; i >= a; --i)
#define REP(i, N) for(int i = 0; i < N; ++i)
#define RREP(i, N) for(int i = N-1; i >= 0; --i)
#define FORIT(i, a) for( TI(a) i = a.begin(); i != a.end(); i++ )

#define PB push_back
#define MP make_pair

template<typename T> T inline SQR( const T &a ){ return a*a; }
template<typename T> T inline ABS( const T &a ){ return a < 0 ? -a : a; }
template<typename T> T inline MIN( const T& a, const T& b){ if( a < b ) return a; return b; }
template<typename T> T inline MAX( const T& a, const T& b){ if( a > b ) return a; return b; }

const double EPS = 1e-9;
inline int SGN( double a ){ return a > EPS ? 1 : (a < -EPS ? -1 : 0); }
inline int CMP( double a, double b ){ return SGN(a - b); }

typedef long long int64;
typedef unsigned long long uint64;

using namespace std;

#define MAXM 100100

int N, M;

struct bus_t{
	int s, t;
	bus_t( int ss = 0, int tt = 0 ) : s(ss), t(tt) {}
	bool operator < ( const bus_t& b ) const {
		if( t != b.t ) return b < b.t;
		return s < b.s;
	}
};

bus_t bus[MAXM];

const int64 MOD = 1000000007LL;

int bit[2*MAXM + 1];
void up( int x, int tt ){
	while( x <= (2*MAXM) ){
		bit[x] = bit[x] + tt;
		bit[x] %= MOD;
		x += ( x & -x );
	}
}

int get( int x ){
	int ans = 0;
	while( x > 0 ){
		ans += bit[x];
		ans %= MOD;
		x -= ( x & -x );
	}
	return ans;
}

int main( int argc, char* argv[] ){

	ios::sync_with_stdio( false );

	cin >> N >> M;

	map< int, int > occ;
	REP( i, M ){
		cin >> bus[i].s >> bus[i].t;
		occ[ bus[i].s ]++;
		occ[ bus[i].t ]++;
	}
	occ[ 0 ]++; bus[M].s = 0, bus[M].t = 0;;
	sort( bus, bus+M );

	map< int, int > id;
	int cid = 0;
	FORIT( x, occ ) id[ x->first ] = cid++;

	up( 0, 1 );
	FOR( i, 1, M ){
		up( bus[i].t, get( bus[i].t-1 ) + get( bus[i].s -1 ) % MOD );
	}

	if( id.find( N ) != id.end() ) cout << get( id[N] ) - get( id[N] - 1 ) << "\n";
	else cout << 0 << endl;
	return 0;
}