#include <iostream>
#include <cstdio>
#include <fstream>

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <cstring>

#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <memory.h>
using namespace std;

#define fr(i, n) for (int i = 0; i < (int)(n); i++)
#define fb(i, n) for (int i = n - 1; i >= 0; i--)
#define mp make_pair
#define pb push_back

const int MAXN = 100100;

int n, c;
int a[MAXN], b[MAXN];
unsigned long long l, r, res, ll, rr;

int main() {
	cin >> n >> c;
	fr(i, n) cin >> a[i] >> b[i];
	l = 0, r = (1LL << 63);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 >= c) {
				cur = -1;
				break;
			} else {
				cur += res * a[i] / b[i] + 1;
				if (cur >= c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}
	ll = l;
	long long buf = 0;
	fr(i, n) {
		if ((ll * a[i]) / b[i] + 1 >= c) {
			buf = -1;
			break;
		} else {
			buf += ll * a[i] / b[i] + 1;
			if (buf >= c) {
				buf = -1;
				break;
			}
		}
	}
	if (buf < c)
		ll++;

	l = 0, r = (1LL << 63);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 > c) {
				cur = -1;
				break;
			} else {
				cur += res * a[i] / b[i] + 1;
				if (cur > c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}
	rr = l;
	buf = 0;
	fr(i, n) {
		if ((rr * a[i]) / b[i] + 1 >= c) {
			buf = -1;
			break;
		} else {
			buf += rr * a[i] / b[i] + 1;
			if (buf >= c) {
				buf = -1;
				break;
			}
		}
	}
	if (buf <= c)
		rr++;
	cout << rr - ll << endl;
	//cerr << ll << " " << rr << endl;
}


#include <iostream>
#include <cstdio>
#include <fstream>

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <cstring>

#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <memory.h>
using namespace std;

#define fr(i, n) for (int i = 0; i < (int)(n); i++)
#define fb(i, n) for (int i = n - 1; i >= 0; i--)
#define mp make_pair
#define pb push_back

const int MAXN = 100100;

int n, c;
int a[MAXN], b[MAXN];
long long l, r, res, ll, rr;

int main() {
	cin >> n >> c;
	fr(i, n) cin >> a[i] >> b[i];
	l = 0, r = (1LL << 62);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 >= c) {
				cur = -1;
				break;
			} else {
				cur += res * a[i] / b[i] + 1;
				if (cur >= c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}
	ll = l;
	long long buf = 0;
	fr(i, n) {
		if ((ll * a[i]) / b[i] + 1 >= c) {
			buf = -1;
			break;
		} else {
			buf += ll * a[i] / b[i] + 1;
			if (buf >= c) {
				buf = -1;
				break;
			}
		}
	}
	if (buf < c)
		ll++;

	l = 0, r = (1LL << 62);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 > c) {
				cur = -1;
				break;
			} else {
				cur += res * a[i] / b[i] + 1;
				if (cur > c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}
	rr = l;
	buf = 0;
	fr(i, n) {
		if ((rr * a[i]) / b[i] + 1 >= c) {
			buf = -1;
			break;
		} else {
			buf += rr * a[i] / b[i] + 1;
			if (buf >= c) {
				buf = -1;
				break;
			}
		}
	}
	if (buf <= c)
		rr++;
	cout << rr - ll << endl;
	//cerr << ll << " " << rr << endl;
}


#include <iostream>
#include <cstdio>
#include <fstream>

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <cstring>

#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <memory.h>
using namespace std;

#define fr(i, n) for (int i = 0; i < (int)(n); i++)
#define fb(i, n) for (int i = n - 1; i >= 0; i--)
#define mp make_pair
#define pb push_back

const int MAXN = 100100;

int n, c;
int a[MAXN], b[MAXN];
long long l, r, res, ll, rr;

int main() {
	cin >> n >> c;
	fr(i, n) cin >> a[i] >> b[i];
	l = 0, r = (1LL << 62);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 >= c) {
				cur = -1;
				break;
			} else {
				cur += res * a[i] / b[i] + 1;
				if (cur >= c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}
	ll = l;
	while (true) {
		long long buf = 0;
		fr(i, n) {
			if ((ll * a[i]) / b[i] + 1 >= c) {
				buf = -1;
				break;
			} else {
				buf += ll * a[i] / b[i] + 1;
				if (buf >= c) {
					buf = -1;
					break;
				}
			}
		}
		if (buf < c && buf != -1)
			ll++;
		else
			break;
		//cerr << ll << endl;
	}

	l = 0, r = (1LL << 62);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 > c) {
				cur = -1;
				break;
			} else {
				cur += res * a[i] / b[i] + 1;
				if (cur > c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}

	rr = l;
	while (true) {
		long long buf = 0;
		fr(i, n) {
			if ((rr * a[i]) / b[i] + 1 > c) {
				buf = -1;
				break;
			} else {
				buf += rr * a[i] / b[i] + 1;
				if (buf > c) {
					buf = -1;
					break;
				}
			}
		}
		if (buf <= c && buf != -1)
			rr++;
		else
			break;
	}

	cout << max(rr - ll, 0LL) << endl;
	//cerr << ll << " " << rr << endl;
}


#include <iostream>
#include <cstdio>
#include <fstream>

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <cstring>

#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <memory.h>
using namespace std;

#define fr(i, n) for (int i = 0; i < (int)(n); i++)
#define fb(i, n) for (int i = n - 1; i >= 0; i--)
#define mp make_pair
#define pb push_back

const int MAXN = 100100;

int n, c;
int a[MAXN], b[MAXN];
long long l, r, res, ll, rr;

int main() {
	cin >> n >> c;
	fr(i, n) cin >> a[i] >> b[i];
	l = 0, r = (1LL << 61);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 >= c) {
				cur = -1;
				break;
			} else {
				cur += (res * a[i]) / b[i] + 1;
				if (cur >= c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}
	ll = l;
	while (true) {
		long long buf = 0;
		fr(i, n) {
			if ((ll * a[i]) / b[i] + 1 >= c) {
				buf = -1;
				break;
			} else {
				buf += (ll * a[i]) / b[i] + 1;
				if (buf >= c) {
					buf = -1;
					break;
				}
			}
		}
		if (buf < c && buf != -1)
			ll++;
		else
			break;
		//cerr << ll << endl;
	}

	l = 0, r = (1LL << 61);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 > c) {
				cur = -1;
				break;
			} else {
				cur += (res * a[i]) / b[i] + 1;
				if (cur > c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}

	rr = l;
	while (true) {
		long long buf = 0;
		fr(i, n) {
			if ((rr * a[i]) / b[i] + 1 > c) {
				buf = -1;
				break;
			} else {
				buf += (rr * a[i]) / b[i] + 1;
				if (buf > c) {
					buf = -1;
					break;
				}
			}
		}
		if (buf <= c && buf != -1)
			rr++;
		else
			break;
	}

	cout << max(rr - ll, 0LL) << endl;
	//cerr << ll << " " << rr << endl;
}


#include <iostream>
#include <cstdio>
#include <fstream>

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <cstring>

#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <memory.h>
using namespace std;

#define fr(i, n) for (int i = 0; i < (int)(n); i++)
#define fb(i, n) for (int i = n - 1; i >= 0; i--)
#define mp make_pair
#define pb push_back

const int MAXN = 100100;

int n, c;
int a[MAXN], b[MAXN];
long long l, r, res, ll, rr;

int main() {
	cin >> n >> c;
	fr(i, n) cin >> a[i] >> b[i];
	l = 0, r = (1LL << 61);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 >= c) {
				cur = -1;
				break;
			} else {
				cur += (res * a[i]) / b[i] + 1;
				if (cur >= c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}
	ll = l;
	while (true) {
		long long buf = 0;
		fr(i, n) {
			if ((ll * a[i]) / b[i] + 1 >= c) {
				buf = -1;
				break;
			} else {
				buf += (ll * a[i]) / b[i] + 1;
				if (buf >= c) {
					buf = -1;
					break;
				}
			}
		}
		if (buf < c && buf != -1)
			ll++;
		//else
			break;
		//cerr << ll << endl;
	}

	l = 0, r = (1LL << 61);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 > c) {
				cur = -1;
				break;
			} else {
				cur += (res * a[i]) / b[i] + 1;
				if (cur > c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}

	rr = l;
	while (true) {
		long long buf = 0;
		fr(i, n) {
			if ((rr * a[i]) / b[i] + 1 > c) {
				buf = -1;
				break;
			} else {
				buf += (rr * a[i]) / b[i] + 1;
				if (buf > c) {
					buf = -1;
					break;
				}
			}
		}
		if (buf <= c && buf != -1)
			rr++;
		//else
			break;
	}

	cout << max(rr - ll, 0LL) << endl;
	//cerr << ll << " " << rr << endl;
}


#include <iostream>
#include <cstdio>
#include <fstream>

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <cstring>

#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <memory.h>
using namespace std;

#define fr(i, n) for (int i = 0; i < (int)(n); i++)
#define fb(i, n) for (int i = n - 1; i >= 0; i--)
#define mp make_pair
#define pb push_back

const int MAXN = 100100;

int n, c;
int a[MAXN], b[MAXN];
long long l, r, res, ll, rr;

int main() {
	cin >> n >> c;
	fr(i, n) cin >> a[i] >> b[i];
	l = 0, r = (1LL << 62);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 >= c) {
				cur = -1;
				break;
			} else {
				cur += (res * a[i]) / b[i] + 1;
				if (cur >= c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}
	ll = l;
	while (true) {
		long long buf = 0;
		fr(i, n) {
			if ((ll * a[i]) / b[i] + 1 >= c) {
				buf = -1;
				break;
			} else {
				buf += (ll * a[i]) / b[i] + 1;
				if (buf >= c) {
					buf = -1;
					break;
				}
			}
		}
		if (buf < c && buf != -1)
			ll++;
		else
			break;
		//cerr << ll << endl;
	}

	l = 0, r = (1LL << 62);
	r--;
	r <<= 1;
	r++;
	while (l < r - 1) {
		res = (l + r) >> 1;
		long long cur = 0;
		fr(i, n) {
			if ((res * a[i]) / b[i] + 1 > c) {
				cur = -1;
				break;
			} else {
				cur += (res * a[i]) / b[i] + 1;
				if (cur > c) {
					cur = -1;
					break;
				}
			}
		}
		if (cur == -1)
			r = res;
		else
			l = res;
	}

	rr = l;
	while (true) {
		long long buf = 0;
		fr(i, n) {
			if ((rr * a[i]) / b[i] + 1 > c) {
				buf = -1;
				break;
			} else {
				buf += (rr * a[i]) / b[i] + 1;
				if (buf > c) {
					buf = -1;
					break;
				}
			}
		}
		if (buf <= c && buf != -1)
			rr++;
		else
			break;
	}

	cout << max(rr - ll, 0LL) << endl;
	//cerr << ll << " " << rr << endl;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }
#define mp(x, y) make_pair(x, y)

ll n, c;
vector<ll> a, b;

void solve() {
    ll minC = n, sumA = 0;
    for(int i = 0; i < n; i++) {
        minC += a[i] / b[i];
        sumA += a[i];
    }

    if(sumA == 0) {
        if(c == n) {
            cout << -1 << endl;
        } else {
            cout << 0 << endl;
        }
        return;
    }

    if(c < minC) {
        cout << 0 << endl;
        return;
    }

    ll xl = 1, xr = (1000000000000000000LL+sumA) / sumA, x = 0;
    while(xl <= xr) {
        ll xm = (xl+xr) / 2;

        ll currC = n;
        for(int i = 0; i < n; i++) {
            currC += (xm * a[i]) / b[i];
        }

        if(currC > c) {
            xr = xm-1;
        } else if(currC < c) {
            xl = xm+1;
        } else {
            x = xm;
            break;
        }
    }

    if(x == 0) {
        cout << 0 << endl;
    } else {
        ll minX = -1, maxX = 1000000000000000005LL;
        for(int i = 0; i < n; i++) {
            ll ci = (x*a[i])/b[i];

            ll minT = b[i] * ci, maxT = minT + b[i]-1;
            minX = max(minX, (minT+a[i]-1)/a[i]);
            maxX = min(maxX, maxT/a[i]);
        }

        cout << maxX - minX + 1 << endl;
    }
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> c) {
        a = vector<ll>(n);
        b = vector<ll>(n);
        for(int i = 0; i < n; i++) {
            scanf("%d %d", &a[i], &b[i]);
        }
        solve();
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }
#define mp(x, y) make_pair(x, y)

ll n, c;
vector<ll> a, b;

void solve() {
    ll minC = n, sumA = 0;
    for(int i = 0; i < n; i++) {
        minC += a[i] / b[i];
        sumA += a[i];
    }

    if(sumA == 0) {
        if(c == n) {
            cout << -1 << endl;
        } else {
            cout << 0 << endl;
        }
        return;
    }

    if(c < minC) {
        cout << 0 << endl;
        return;
    }

    ll xl = 1, xr = (1000000000000000000LL+sumA) / sumA, x = 0;
    while(xl <= xr) {
        ll xm = (xl+xr) / 2;

        ll currC = n;
        for(int i = 0; i < n; i++) {
            currC += (xm * a[i]) / b[i];
        }

        if(currC > c) {
            xr = xm-1;
        } else if(currC < c) {
            xl = xm+1;
        } else {
            x = xm;
            break;
        }
    }

    if(x == 0) {
        cout << 0 << endl;
    } else {
        ll minX = 1, maxX = 1000000000000000005LL;
        for(int i = 0; i < n; i++) {
            if(a[i] == 0) {
                continue;
            }

            ll ci = (x*a[i])/b[i];

            ll minT = b[i] * ci, maxT = minT + b[i]-1;
            minX = max(minX, (minT+a[i]-1)/a[i]);
            maxX = min(maxX, maxT/a[i]);
        }

//      cout << "! " << minX << ' ' << maxX << endl;
        cout << maxX - minX + 1 << endl;
    }
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> c) {
        a = vector<ll>(n);
        b = vector<ll>(n);
        for(int i = 0; i < n; i++) {
            scanf("%d %d", &a[i], &b[i]);
        }
        solve();
    }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <functional>
#include <limits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;

const double pi = acos(-1.0);

#define oned(a, x1, x2) { cout << #a << ":"; for(int _i = (x1); _i < (x2); _i++){ cout << " " << a[_i]; } cout << endl; }
#define twod(a, x1, x2, y1, y2) { cout << #a << ":" << endl; for(int _i = (x1); _i < (x2); _i++){ for(int _j = (y1); _j < (y2); _j++){ cout << (_j > y1 ? " " : "") << a[_i][_j]; } cout << endl; } }
#define mp(x, y) make_pair(x, y)

int n, c;
vector<ll> a, b;

void solve() {
    ll minC = n, maxA = 0;
    for(int i = 0; i < n; i++) {
        minC += a[i] / b[i];
        maxA = max(maxA, a[i]);
    }

    if(maxA == 0) {
        if(c == n) {
            cout << -1 << endl;
        } else {
            cout << 0 << endl;
        }
        return;
    }

    if(c < minC) {
        cout << 0 << endl;
        return;
    }

    ll xl = 1, xr = (1000000000000000000LL+maxA-1) / maxA, x = 0;
    while(xl <= xr) {
        ll xm = (xl+xr) / 2;
//      cout << xl << ' ' << xr << " : " << xm << endl;

        ll currC = n;
        for(int i = 0; i < n; i++) {
            currC += (xm * a[i]) / b[i];
        }
//      cout << currC << endl;
        if(currC > c) {
            xr = xm-1;
        } else if(currC < c) {
            xl = xm+1;
        } else {
            x = xm;
            break;
        }
    }

    ll minX = -1, maxX = 1000000000000000005LL;
    for(int i = 0; i < n; i++) {
        ll ci = (x*a[i])/b[i];

        ll minT = b[i] * ci, maxT = minT + b[i]-1;
        minX = max(minX, (minT+a[i]-1)/a[i]);
        maxX = min(maxX, maxT/a[i]);
    }

    cout << maxX - minX + 1 << endl;
}

int main() {
//  freopen("input.in", "r", stdin);
    while(cin >> n >> c) {
        a = vector<ll>(n);
        b = vector<ll>(n);
        for(int i = 0; i < n; i++) {
            scanf("%d %d", &a[i], &b[i]);
        }
        solve();
    }
}


#include <iostream>

using namespace std;

typedef long long ll;
const ll maxn = 10000+10;
ll n,c,fi,se,p[maxn],a[maxn];
bool mark;

ll check (ll x)
{
    ll ans=0;
    if (x == -1) return 0;
    for (ll i=0;i<n;i++)
        ans += ll(((long double)a[i]*(long double)x)/(long double)p[i])+1;
    return ans;
}

int main()
{
    cin >> n >> c;
    for (ll i=0;i<n;i++){
        cin >> a[i] >> p[i];
        if (a[i] != 0) mark=true;
    }
    if (!mark) {
       cout << -1 << endl;
       return 0;
    }
    ll st=-1,en= 100000000000000000ll;
    while (st < en-1){
          ll mid = (st+en)/2;
          if (check(mid) > c) en = mid;
          else st = mid;
    }
    se = st;
    st =0,en=100000000000000000ll;
    while (st < en-1){
          ll mid = (st+en )/2;
          if (check(mid) < c) st = mid;
          else en = mid;
    }
    if (check (st) >= c) fi = st ;
    else fi = en;
    cout << se-fi+1 << endl;
    while (mark);
    return 0;
}


#include <iostream>

using namespace std;

typedef long long ll;
const ll maxn = 10000+10;
ll n,c,fi,se,p[maxn],a[maxn];
bool mark;

ll check (ll x)
{
    ll ans=0;
    if (x == -1) return 0;
    for (ll i=0;i<n;i++)
        ans += ll(((long double)a[i]*(long double)x)/(long double)p[i])+1;
    return ans;
}

int main()
{
    cin >> n >> c;
    for (ll i=0;i<n;i++){
        cin >> a[i] >> p[i];
        if (a[i] != 0) mark=true;
    }
    if (!mark) {
       cout << -1 << endl;
       return 0;
    }
    ll st=-1,en= 100000000000000000ll;
    while (st < en-1){
          ll mid = (st+en)/2;
          if (check(mid) > c) en = mid;
          else st = mid;
    }
    se = st;
    st =0,en=100000000000000000ll;
    while (st < en-1){
          ll mid = (st+en )/2;
          if (check(mid) < c) st = mid;
          else en = mid;
    }
    if (check (st) >= c) fi = st ;
    else fi = en;
    cout << se-fi+1 << endl;
    //while (mark);
    return 0;
}


#include <iostream>

using namespace std;

typedef long long ll;
const ll maxn = 10000+10;
ll n,c,fi,se,p[maxn],a[maxn];
bool mark;

ll check (ll x)
{
    ll ans=0;
    for (ll i=0;i<n;i++)
        ans += ll(((long double)a[i]*(long double)x)/(long double)p[i])+1;
    return ans;
}

int main()
{
    cin >> n >> c;
    for (ll i=0;i<n;i++){
        cin >> a[i] >> p[i];
        if (a[i] != 0) mark=true;
    }
    if (!mark) {
       cout << -1 << endl;
       return 0;
    }
    ll st=0,en= 100000000000000000ll;
    while (st < en -1){
          ll mid = (st+en)/2;
          if (check(mid) > c) en = mid;
          else st = mid;
    }
    se = st;
    st =0,en=100000000000000000ll;
    while (st < en-1){
          ll mid = (st+en )/2;
          if (check(mid) < c) st = mid;
          else en = mid;
    }
    if (check (st) >= c) fi = st ;
    else fi = en;
    cout << se-fi+1 << endl;
    return 0;
}


#include <iostream>

using namespace std;

typedef long long ll;
const ll maxn = 10000+10;
ll n,c,fi,se,p[maxn],a[maxn];
bool mark;

ll check (ll x)
{
    ll ans=0;
    if (x == 0) return 0;
    for (ll i=0;i<n;i++)
        ans += ll(((long double)a[i]*(long double)x)/(long double)p[i])+1;
    return ans;
}

int main()
{
    cin >> n >> c;
    for (ll i=0;i<n;i++){
        cin >> a[i] >> p[i];
        if (a[i] != 0) mark=true;
    }
    if (!mark) {
       cout << -1 << endl;
       return 0;
    }
    ll st=0,en= 100000000000000000ll;
    while (st < en-1){
          ll mid = (st+en)/2;
          if (check(mid) > c) en = mid;
          else st = mid;
    }
    se = st;
    st =0,en=100000000000000000ll;
    while (st < en-1){
          ll mid = (st+en )/2;
          if (check(mid) < c) st = mid;
          else en = mid;
    }
    if (check (st) >= c) fi = st ;
    else fi = en;
    cout << se-fi+1 << endl;
    //while (mark);
    return 0;
}


/*
ID: indeed2008
PROG: 04/21/2012 ABBYY Cup 2.0 - Easy E. Space Voyage
LANG: C++
STATUS: accepted
RUN TIME: 0.008
CATERGORY: binary search
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <utility>
#include <bitset>
#include <numeric>

using namespace std;

#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define epsilon 1e-9
// **********************
//      01/24/2013
// **********************
#define JUDGE 1
#define maxn 10005

typedef pair<long long, long long> pll;
pll p[maxn];
long long n;

bool comp(pll p1, pll p2){
  return p1.first*p2.second < p1.second*p2.first;
}

long long compDays(long long x){
  long long ret = n;
  long long i;
  for (i = 0; i < n; ++i)
    ret += (p[i].first*x)/p[i].second;
  return ret;
}

int main()
{
#ifndef JUDGE
  FILE *fin = freopen("input.txt", "r", stdin);
  FILE *fout = freopen("output.txt", "w", stdout);
#endif

  int i;
  long long c, a, b;
  scanf("%d%I64d", &n, &c);
  for (i = 0; i < n; ++i){
    scanf("%I64d%I64d", &a, &b);
    p[i] = pll(a, b);
  }
  sort(p, p + n, comp);
  if (c < n){
    printf("0\n");
    return 0;
  }
  long long high = c*(p[0].second+p[0].first+5)/p[0].first;
  long long first = 1, cnt = high, step, mid;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days < c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  if ( compDays(first) != c){
     printf("0\n");
     return 0;
  }
  long long low = first;
  cnt = high - first + 1;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days <= c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  printf("%I64d\n", first - low);

#ifndef JUDGE
  fclose(fin);
  fclose(fout);
#endif
  return 0;
}


/*
ID: indeed2008
PROG: 04/21/2012 ABBYY Cup 2.0 - Easy E. Space Voyage
LANG: C++
STATUS: accepted
RUN TIME: 0.008
CATERGORY: binary search
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <utility>
#include <bitset>
#include <numeric>

using namespace std;

#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define epsilon 1e-9
// **********************
//      01/24/2013
// **********************
#define JUDGE 1
#define maxn 10005

typedef pair<long long, long long> pll;
pll p[maxn];
long long n;

bool comp(pll p1, pll p2){
  return p1.first*p2.second < p1.second*p2.first;
}

long long compDays(long long x){
  long long ret = n;
  long long i;
  for (i = 0; i < n; ++i)
    ret += (p[i].first*x)/p[i].second;
  return ret;
}

int main()
{
#ifndef JUDGE
  FILE *fin = freopen("input.txt", "r", stdin);
  FILE *fout = freopen("output.txt", "w", stdout);
#endif

  int i;
  long long c, a, b;
  scanf("%d%I64d", &n, &c);
  for (i = 0; i < n; ++i){
    scanf("%I64d%I64d", &a, &b);
    p[i] = pll(a, b);
  }
  sort(p, p + n, comp);
  if (c < n){
    printf("0\n");
    return 0;
  }
  long long high = (c - n)*(p[0].second+p[0].first+5)/p[0].first;
  long long first = 1, cnt = high, step, mid;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days < c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  if ( compDays(first) != c){
     printf("0\n");
     return 0;
  }
  long long low = first;
  cnt = high - first + 1;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days <= c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  printf("%I64d\n", first - low);

#ifndef JUDGE
  fclose(fin);
  fclose(fout);
#endif
  return 0;
}


/*
ID: indeed2008
PROG: 04/21/2012 ABBYY Cup 2.0 - Easy E. Space Voyage
LANG: C++
STATUS: accepted
RUN TIME: 0.008
CATERGORY: binary search
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <utility>
#include <bitset>
#include <numeric>

using namespace std;

#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define epsilon 1e-9
// **********************
//      01/24/2013
// **********************
#define JUDGE 1
#define maxn 10005

typedef pair<long long, long long> pll;
pll p[maxn];
long long n;

bool comp(pll p1, pll p2){
  return p1.first*p2.second < p1.second*p2.first;
}

long long compDays(long long x){
  long long ret = n;
  long long i;
  for (i = 0; i < n; ++i)
    ret += (p[i].first*x)/p[i].second;
  return ret;
}

int main()
{
#ifndef JUDGE
  FILE *fin = freopen("input.txt", "r", stdin);
  FILE *fout = freopen("output.txt", "w", stdout);
#endif

  int i;
  long long c, a, b;
  scanf("%d%I64d", &n, &c);
  for (i = 0; i < n; ++i){
    scanf("%I64d%I64d", &a, &b);
    p[i] = pll(a, b);
  }
  sort(p, p + n, comp);
  if (c < n){
    printf("0\n");
    return 0;
  }
  long long high = (c - n)*(p[0].second+p[0].first+5)/p[0].first;
  long long first = 0, cnt = high, step, mid;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days < c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  if ( compDays(first) != c){
     printf("0\n");
     return 0;
  }
  long long low = first;
  cnt = high - first + 1;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days <= c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  printf("%I64d\n", first - low);

#ifndef JUDGE
  fclose(fin);
  fclose(fout);
#endif
  return 0;
}


/*
ID: indeed2008
PROG: 04/21/2012 ABBYY Cup 2.0 - Easy E. Space Voyage
LANG: C++
STATUS: accepted
RUN TIME: 0.008
CATERGORY: binary search
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <utility>
#include <bitset>
#include <numeric>

using namespace std;

#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define epsilon 1e-9
// **********************
//      01/24/2013
// **********************
#define JUDGE 1
#define maxn 10005

typedef pair<long long, long long> pll;
pll p[maxn];
long long n;

bool comp(pll p1, pll p2){
  return p1.first*p2.second < p1.second*p2.first;
}

long long compDays(long long x){
  long long ret = n;
  long long i;
  for (i = 0; i < n; ++i)
    ret += (p[i].first*x)/p[i].second;
  return ret;
}

int main()
{
#ifndef JUDGE
  FILE *fin = freopen("input.txt", "r", stdin);
  FILE *fout = freopen("output.txt", "w", stdout);
#endif

  int i;
  long long c, a, b;
  scanf("%d%I64d", &n, &c);
  for (i = 0; i < n; ++i){
    scanf("%I64d%I64d", &a, &b);
    p[i] = pll(a, b);
  }
  sort(p, p + n, comp);
  if (c < n){
    printf("0\n");
    return 0;
  }
  long long high = (c - n)*(p[0].second+p[0].first+5)/p[0].first;
  long long first = 0, cnt = high, step, mid;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days < c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  if ( first == 0 || compDays(first) != c){
     printf("0\n");
     return 0;
  }
  long long low = first;
  cnt = high - first + 1;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days <= c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  printf("%I64d\n", first - low);

#ifndef JUDGE
  fclose(fin);
  fclose(fout);
#endif
  return 0;
}


/*
ID: indeed2008
PROG: 04/21/2012 ABBYY Cup 2.0 - Easy E. Space Voyage
LANG: C++
STATUS: accepted
RUN TIME: 0.008
CATERGORY: binary search
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <utility>
#include <bitset>
#include <numeric>

using namespace std;

#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define epsilon 1e-9
// **********************
//      01/24/2013
// **********************
#define JUDGE 1
#define maxn 10005

typedef pair<long long, long long> pll;
pll p[maxn];
long long n;

bool comp(pll p1, pll p2){
  return p1.first*p2.second < p1.second*p2.first;
}

long long compDays(long long x){
  long long ret = n;
  long long i;
  for (i = 0; i < n; ++i)
    ret += (p[i].first*x)/p[i].second;
  return ret;
}

int main()
{
#ifndef JUDGE
  FILE *fin = freopen("input.txt", "r", stdin);
  FILE *fout = freopen("output.txt", "w", stdout);
#endif

  int i;
  long long c, a, b;
  scanf("%d%I64d", &n, &c);
  for (i = 0; i < n; ++i){
    scanf("%I64d%I64d", &a, &b);
    p[i] = pll(a, b);
  }
  sort(p, p + n, comp);
  if (c < n){
    printf("0\n");
    return 0;
  }
  long long high = (c - n)*p[0].second/p[0].first + 2;
  long long first = 0, cnt = high, step, mid;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days < c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  if ( compDays(first) != c){
     printf("0\n");
     return 0;
  }
  long long low = first;
  cnt = high - first + 1;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days <= c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  printf("%I64d\n", first - low);

#ifndef JUDGE
  fclose(fin);
  fclose(fout);
#endif
  return 0;
}


/*
ID: indeed2008
PROG: 04/21/2012 ABBYY Cup 2.0 - Easy E. Space Voyage
LANG: C++
STATUS: accepted
RUN TIME: 0.008
CATERGORY: binary search
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <utility>
#include <bitset>
#include <numeric>

using namespace std;

#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define epsilon 1e-9
// **********************
//      01/24/2013
// **********************
//#define JUDGE 1
#define maxn 10005

typedef pair<long long, long long> pll;
pll p[maxn];
long long n;

bool comp(pll p1, pll p2){
  return p1.first*p2.second < p1.second*p2.first;
}

long long compDays(long long x){
  long long ret = n;
  long long i;
  for (i = 0; i < n; ++i)
    ret += (p[i].first*x)/p[i].second;
  return ret;
}

int main()
{
#ifndef JUDGE
  FILE *fin = freopen("input.txt", "r", stdin);
  FILE *fout = freopen("output.txt", "w", stdout);
#endif

  int i;
  long long c, a, b;
  scanf("%d%I64d", &n, &c);
  for (i = 0; i < n; ++i){
    scanf("%I64d%I64d", &a, &b);
    p[i] = pll(a, b);
  }
  sort(p, p + n, comp);
  if (c < n){
    printf("0\n");
    return 0;
  }
  long long high = (c - n)*(p[0].second+p[0].first+5)/p[0].first;
  long long first = 0, cnt = high, step, mid;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days < c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  if ( first == 0 || compDays(first) != c){
     printf("0\n");
     return 0;
  }
  long long low = first;
  cnt = high - first + 1;
  while (cnt > 0){
    step = cnt/2;
    mid = first + step;
    long long days = compDays(mid);
    if (days <= c){
      first = mid + 1;
      cnt -= (step + 1);
    }
    else
      cnt = step;
  }
  printf("%I64d\n", first - low);

#ifndef JUDGE
  fclose(fin);
  fclose(fout);
#endif
  return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair

const double PI = acos(-1.0);
const int INF = 1000000000;
const int MOD = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("INPUT.TXT","r",stdin);
	//freopen("OUTPUT.TXT","w",stdout);
	#endif
	int n,c;
	cin>>n>>c;
	vector<pair<int,int> > mas(n);
	for(int i=0; i<n; i++)
	{
		cin>>mas[i].first>>mas[i].second;
	}
	int d=0;
	int rez=0;
	for(int x=1; x<100005; x++)
	{
		int S=0;
		d=0;
		for(int i=0; i<n; i++)
		{
			if(mas[i].first*x<mas[i].second)
			{
				d++;
				continue;
			}
			else
			{
				d++;
				d+=(mas[i].first*x)/mas[i].second;
			}
		}
		if(d==c)
		{
			rez++;
		}
	}
	cout<<rez;
	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair

const double PI = acos(-1.0);
const int INF = 1000000000;
const int MOD = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("INPUT.TXT","r",stdin);
	//freopen("OUTPUT.TXT","w",stdout);
	#endif
	int n,c;
	cin>>n>>c;
	vector<pair<int,int> > mas(n);
	for(int i=0; i<n; i++)
	{
		cin>>mas[i].first>>mas[i].second;
	}
	int d=0;
	int rez=0;
	for(int x=1; x<100005; x++)
	{
		int S=0;
		d=0;
		for(int i=0; i<n; i++)
		{
			if(mas[i].first*x<mas[i].second)
			{
				continue;
			}
			else
			{
				d++;
				d+=mas[i].first*x/mas[i].second;
			}
		}
		if(d==c)
		{
			rez++;
		}
	}
	if(rez>10005)
	{
		cout<<-1;
	}
	else
	{
		cout<<rez;
	}
	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair

const double PI = acos(-1.0);
const int INF = 1000000000;
const int MOD = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("INPUT.TXT","r",stdin);
	//freopen("OUTPUT.TXT","w",stdout);
	#endif
	int n,c;
	cin>>n>>c;
	vector<pair<int,int> > mas(n);
	for(int i=0; i<n; i++)
	{
		cin>>mas[i].first>>mas[i].second;
	}
	int d=0;
	int rez=0;
	for(int x=1; x<10005; x++)
	{
		int S=0;
		d=0;
		for(int i=0; i<n; i++)
		{
			if(mas[i].first*x<mas[i].second)
			{
				continue;
			}
			else
			{
				d++;
				d+=mas[i].first*x/mas[i].second;
			}
		}
		if(d==c)
		{
			rez++;
		}
	}
	cout<<rez;
	return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
    ll n,c;
    cin >> n >> c;

    ll asum = 0;

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

    if(n == c && asum == 0) return -1;

    int num = 0;
    for(int i=0; i<10000; ++i){
        int days = n;
        for(int j=0; j<n; ++j){
            days += a[j]*i/b[j];
        }
        if(days == c) {
            num++;
        }
    }

    cout << num << endl;
    return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
    ll n,c;
    cin >> n >> c;

    ll asum = 0, bsum = 0, m = 0;

    for(int i=0; i<n; ++i){
        cin >> a[i] >> b[i];
        asum += a[i];
        bsum += b[i];
    }

    if(n == c && asum == 0){
        cout << -1 << endl;
        return 0;
    }

    int num = 0;
    for(int i=0; i<2000000; ++i){
        int days = n;
        for(int j=0; j<n; ++j){
            days += a[j]*i/b[j];
        }
        if(days == c) {
            num++;
        }
        if(days > c) break;
    }

    cout << num << endl;
    return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
    ll n,c;
    cin >> n >> c;

    ll asum = 0, bsum = 0, m = 0;

    for(int i=0; i<n; ++i){
        cin >> a[i] >> b[i];
        asum += a[i];
        bsum += b[i];
    }

    if(n == c && asum == 0) return -1;

    int num = 0;
    for(int i=0; i<20000; ++i){
        int days = n;
        for(int j=0; j<n; ++j){
            days += a[j]*i/b[j];
        }
        if(days == c) {
            num++;
        }
    }

    cout << num << endl;
    return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
	ll n,c;
	cin >> n >> c;

	ll asum = 0, bsum = 0, m = 0;

	for(int i=0; i<n; ++i){
		cin >> a[i] >> b[i];
		asum += a[i];
		bsum += b[i];
	}

	if(n == c && asum == 0) return -1;

	int num = 0;
	for(int i=(c-n)*bsum; i<20000; ++i){
		int days = n;
		for(int j=0; j<n; ++j){
			days += a[j]*i/b[j];
		}
		if(days == c) {
			num++;
		}
	}

	cout << num << endl;
	return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
    ll n,c;
    cin >> n >> c;

    ll asum = 0, bsum = 0, m = 0;

    for(int i=0; i<n; ++i){
        cin >> a[i] >> b[i];
        asum += a[i];
        bsum += b[i];
    }

    if(n == c && asum == 0){
        cout << -1 << endl;
        return 0;
    }

    ll num = 0;
    for(int i=1; i<2000000; ++i){
        ll days = n;
        for(int j=0; j<n; ++j){
            days += a[j]*i/b[j];
        }
        if(days == c) {
            num++;
        }
        if(days > c) break;
    }

    cout << num << endl;
    return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
    ll n,c;
    cin >> n >> c;

    ll asum = 0;

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

    if(n == c && asum == 0) return -1;

    int num = 0;
    for(int i=0; i<1000000; ++i){
        int days = n;
        for(int j=0; j<n; ++j){
            days += a[j]*i/b[j];
        }
        if(days == c) {
            num++;
        }
    }

    cout << num << endl;
    return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
    ll n,c;
    cin >> n >> c;

    ll asum = 0;

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

    if(n == c && asum == 0) return -1;

    int num = 0;
    for(int i=0; i<100; ++i){
        int days = n;
        for(int j=0; j<n; ++j){
            days += a[j]*i/b[j];
        }
        if(days == c) {
            num++;
        }
    }

    cout << num << endl;
    return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
    ll n,c;
    cin >> n >> c;

    ll asum = 0, bsum = 0, m = 0;

    for(int i=0; i<n; ++i){
        cin >> a[i] >> b[i];
        asum += a[i];
        bsum += b[i];
    }

    if(n == c && asum == 0){
        cout << -1 << endl;
        return 0;
    }

    ll num = 0;
    for(int i=0; i<2000000; ++i){
        ll days = n;
        for(int j=0; j<n; ++j){
            ll pre = a[j] * i;
            while(pre >= b[j]){
                pre -= b[j];
                days++;
            }
        }
        if(days == c) {
            num++;
        }
        if(days > c) break;
    }

    cout << num << endl;
    return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
	ll n,c;
	cin >> n >> c;

	ll asum = 0;

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

	if(n == c && asum == 0) return -1;

	int num = 0;
	for(int i=0; i<100; ++i){
		int days = n;
		for(int j=0; j<n; ++j){
			days += a[j]*i/b[j];
		}
		if(days == c) {
			cout << i << endl;
			num++;
		}
	}

	cout << num << endl;
	return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
	ll n,c;
	cin >> n >> c;

	ll asum = 0;

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

	if(n == c && asum == 0) return -1;

	int num = 0;
	for(int i=0; i<100; ++i){
		int days = n;
		for(int j=0; j<n; ++j){
			days += a[j]*i/b[j];
		}
		if(days == c) num++;
	}

	cout << num << endl;

	return 0;
}


#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll a[10000], b[10000];

int main(void){
    ll n,c;
    cin >> n >> c;

    ll asum = 0;

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

    if(n == c && asum == 0) return -1;

    int num = 0;
    for(int i=0; i<20000; ++i){
        int days = n;
        for(int j=0; j<n; ++j){
            days += a[j]*i/b[j];
        }
        if(days == c) {
            num++;
        }
    }

    cout << num << endl;
    return 0;
}


#include <stdio.h>

typedef long long ll;

const int MAXN = 1e4+10 ;
const ll inf = 2*1e9 ;

struct city{

	ll a,b;

	void inp(){

		scanf(" %I64d %I64d",&a,&b);

	}

}ar[MAXN];

int N
ll C;

void read(){

	int i;

	scanf(" %d %I64d",&N,&C);

	for( i=1 ; i<=N ; i++ )
		ar[i].inp();

}

ll calc(ll x){

	int i;
	ll res=0;

	for( i=1 ; i<=N ; i++ )
		res+=ar[i].a*x/ar[i].b+1;

	return res;

}

ll searchleft(){

	ll l=1,r=inf,m;

	while( l+1<r ){

		m=(l+r)/2;

		if(calc(m) >= C )	r=m;
		else if(calc(m) < C )	l=m;

	}

	return m;

}

ll searchright(){

	ll l=1,r=inf,m;

	while( l+1<r ){

		m=(l+r)/2;

		if(calc(m) > C )	r=m;
		else if(calc(m) <= C )	l=m;

	}

	return m;

}

int main(){

/*	freopen("f.in","r",stdin);
	freopen("f.out","w",stdout);*/

	read();

	printf("%I64d\n",searchright()-searchleft()+1);

	return 0;

}


#include <stdio.h>

typedef long long ll;

const int MAXN = 1e4+10 ;
const ll inf = 2*1e9 ;

struct city{

	ll a,b;

	void inp(){

		scanf(" %I64d %I64d",&a,&b);

	}

}ar[MAXN];

int N;
ll C;

void read(){

	int i;

	scanf(" %d %I64d",&N,&C);

	for( i=1 ; i<=N ; i++ )
		ar[i].inp();

}

ll calc(ll x){

	int i;
	ll res=N;

	for( i=1 ; i<=N ; i++ )
		res+=(ar[i].a*x)/ar[i].b;

	if(res<0)	return C+1111;
	return res;

}

ll searchleft(){

	ll l=1,r=inf,m;

	while( l+1 < r ){

		m=(l+r)/2;

		if(calc(m) >= C)	r=m;
		else l=m;

	}

	return l;

}

ll searchright(){

	ll l=1,r=inf,m;

	while( l+1 < r ){

		m=(l+r)/2;

		if(calc(m) <= C)	l=m;
		else r=m;

	}

	return r;

}

int main(){

#ifndef ONLINE_JUDGE
	freopen("f.in","r",stdin);
	freopen("f.out","w",stdout);
#endif

	read();

	ll min,max;

	max=searchright();
	min=searchleft();

	printf("%I64d\n",max-min-1);

	return 0;

}


#include <stdio.h>

typedef long long ll;

const int MAXN = 1e4+10 ;
const ll inf = 2*1e9 ;

struct city{

	ll a,b;

	void inp(){

		scanf(" %I64d %I64d",&a,&b);

	}

}ar[MAXN];

int N;
ll C;

void read(){

	int i;

	scanf(" %d %I64d",&N,&C);

	for( i=1 ; i<=N ; i++ )
		ar[i].inp();

}

ll calc(ll x){

	int i;
	ll res=N;

	for( i=1 ; i<=N ; i++ )
		res+=(ar[i].a*x)/ar[i].b;

	return res;

}

ll searchleft(){

	ll l=1,r=inf,m;

	while( l+1<r ){

		m=(l+r)/2;

	//	printf("lll ==> l=%lld r=%lld m=%lld clc=%lld\n",l,r,m,calc(m));

		if(calc(m) >= C )	r=m;
		else if(calc(m) < C )	l=m;

	}

	return m;

}

ll searchright(){

	ll l=1,r=inf,m;

	while( l+1<r ){

		m=(l+r)/2;

	//	printf("rrr ==> l=%lld r=%lld m=%lld clc=%lld\n",l,r,m,calc(m));

		if(calc(m) > C )	r=m;
		else if(calc(m) <= C )	l=m;

	}

	return m;

}

int main(){

	/*freopen("f.in","r",stdin);
	freopen("f.out","w",stdout);*/

	read();

	ll min,max;
	ll i;

	max=searchright();
	min=searchleft();
	//printf(" mx=%lld mn=%lld cmn=%lld cmx=%lld\n",max,min,calc(min),calc(max));
	if(calc(max)==C){

		for( i=max ; calc(i)==C ; i++ );
		max=i-1;

	}
	else{

		for( i=max ; calc(i)!=C ; i-- );
		max=i;

	}

	if(calc(min)==C){

		for( i=min ; calc(i)==C ; i-- );
		min=i+1;

	}
	else{

		for( i=min ; calc(i)!=C ; i++ );
		min=i;

	}

//	printf(" mx=%lld mn=%lld cmn=%lld cmx=%lld\n",max,min,calc(min),calc(max));
	printf("%I64d\n",max-min+1);

	/*for( i=min ; i<=max ; i++ )
		printf("%lld %lld ==> %lld\n",i-min+1,i,calc(i));*/

	return 0;

}


#include <stdio.h>

typedef long long ll;

const int MAXN = 1e4+10 ;
const ll inf = 2*1e9 ;

struct city{

	ll a,b;

	void inp(){

		scanf(" %I64d %I64d",&a,&b);

	}

}ar[MAXN];

int N;
ll C;

void read(){

	int i;

	scanf(" %d %I64d",&N,&C);

	for( i=1 ; i<=N ; i++ )
		ar[i].inp();

}

ll calc(ll x){

	int i;
	ll res=0;

	for( i=1 ; i<=N ; i++ )
		res+=ar[i].a*x/ar[i].b+1;

	return res;

}

ll searchleft(){

	ll l=1,r=inf,m;

	while( l+1<r ){

		m=(l+r)/2;

		if(calc(m) >= C )	r=m;
		else if(calc(m) < C )	l=m;

	}

	return m;

}

ll searchright(){

	ll l=1,r=inf,m;

	while( l+1<r ){

		m=(l+r)/2;

		if(calc(m) > C )	r=m;
		else if(calc(m) <= C )	l=m;

	}

	return m;

}

int main(){

/*	freopen("f.in","r",stdin);
	freopen("f.out","w",stdout);*/

	read();

	printf("%I64d\n",searchright()-searchleft()+1);

	return 0;

}


#include <stdio.h>

typedef long long ll;

const int MAXN = 1e4+10 ;
const ll inf = 2*1e9 ;

struct city{

	ll a,b;

	void inp(){

		scanf(" %I64d %I64d",&a,&b);

	}

}ar[MAXN];

int N;
ll C;

void read(){

	int i;

	scanf(" %d %I64d",&N,&C);

	for( i=1 ; i<=N ; i++ )
		ar[i].inp();

}

ll calc(ll x){

	int i;
	ll res=N;

	for( i=1 ; i<=N ; i++ )
		res+=(ar[i].a*x)/ar[i].b;

	return res;

}

ll searchleft(){

	ll l=1,r=inf,m;

	while( l+1<r ){

		m=(l+r)/2;

	//	printf("lll ==> l=%lld r=%lld m=%lld clc=%lld\n",l,r,m,calc(m));

		if(calc(m) >= C )	r=m;
		else if(calc(m) < C )	l=m;

	}

	return m;

}

ll searchright(){

	ll l=1,r=inf,m;

	while( l+1<r ){

		m=(l+r)/2;

	//	printf("rrr ==> l=%lld r=%lld m=%lld clc=%lld\n",l,r,m,calc(m));

		if(calc(m) > C )	r=m;
		else if(calc(m) <= C )	l=m;

	}

	return m;

}

int main(){

/*	freopen("f.in","r",stdin);
	freopen("f.out","w",stdout);
	*/
	read();

	ll min,max;
	ll i;

	max=searchright();
	min=searchleft();
//	printf(" mx=%lld mn=%lld cmn=%lld cmx=%lld\n",max,min,calc(min),calc(max));

	printf("%I64d\n",max-min+1);

	/*for( i=min ; i<=max ; i++ )
		printf("%lld %lld ==> %lld\n",i-min+1,i,calc(i));*/

	return 0;

}


#include <stdio.h>

typedef long long ll;

const int MAXN = 1e4+10 ;
const ll inf = 2*1e9 ;

struct city{

	ll a,b;

	void inp(){

		scanf(" %I64d %I64d",&a,&b);

	}

}ar[MAXN];

int N;
ll C;

void read(){

	int i;

	scanf(" %d %I64d",&N,&C);

	for( i=1 ; i<=N ; i++ )
		ar[i].inp();

}

ll calc(ll x){

	int i;
	ll res=N;

	for( i=1 ; i<=N ; i++ )
		res+=(ar[i].a*x)/ar[i].b;

	if(res<0)	return C+1111;
	return res;

}

ll searchleft(){

	ll l=0,r=inf,m;

	while( l+1 < r ){

		m=(l+r)/2;

		if(calc(m) >= C)	r=m;
		else l=m;

	}

	return l;

}

ll searchright(){

	ll l=0,r=inf,m;

	while( l+1 < r ){

		m=(l+r)/2;

		if(calc(m) <= C)	l=m;
		else r=m;

	}

	return r;

}

int main(){

#ifndef ONLINE_JUDGE
	freopen("f.in","r",stdin);
	freopen("f.out","w",stdout);
#endif

	read();

	ll min,max;

	max=searchright();
	min=searchleft();

	printf("%I64d\n",max-min-1);

	return 0;

}


#include <stdio.h>

typedef long long ll;

const int MAXN = 1e4+10 ;
const ll inf = 2*1e9 ;

struct city{

	ll a,b;

	void inp(){

		scanf(" %I64d %I64d",&a,&b);

	}

}ar[MAXN];

int N;
ll C;

void read(){

	int i;

	scanf(" %d %I64d",&N,&C);

	for( i=1 ; i<=N ; i++ )
		ar[i].inp();

}

ll calc(ll x){

	int i;
	ll res=N;

	for( i=1 ; i<=N ; i++ )
		res+=(ar[i].a*x)/ar[i].b;

	return res;

}

ll searchleft(){

	ll l=1,r=inf,m;

	while( l+1 < r ){

		m=(l+r)/2;

		if(calc(m) >= C)	r=m;
		else l=m;

	}

	return l;

}

ll searchright(){

	ll l=1,r=inf,m;

	while( l+1 < r ){

		m=(l+r)/2;

		if(calc(m) <= C)	l=m;
		else r=m;

	}

	return r;

}

int main(){

#ifndef ONLINE_JUDGE
	freopen("f.in","r",stdin);
	freopen("f.out","w",stdout);
#endif

	read();

	ll min,max;

	max=searchright();
	min=searchleft();

	printf("%I64d\n",max-min-1);

	return 0;

}


#include <iostream>
#include <climits>
#include <cstdio>
#include <cstring>
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define MAX 10000
using namespace std;

typedef unsigned long long ull;
int n, c, a[MAX], b[MAX];

inline ull muldiv(ull a, ull x, ull b) {
	return (a / b) * (x / b) * b +
		   (a / b) * (x % b) +
		   (a % b) * (x / b) +
		   ((a % b) * (x % b)) / b;
}

inline ull query(ull x) {
	ull res = n;
	FOR (i, n) {
		res += muldiv(a[i], x, b[i]);
		if (res > c) return res;
	}
	return res;
}

int main() {
	bool notzero = false;
	scanf("%d%d", &n, &c);
	FOR (i, n) scanf("%d%d", &a[i], &b[i]), notzero |= a[i];

	if (!notzero) printf("%d\n", (c == n) ? -1 : 0);
	else {
		long long l, r, s, e;
		for (s = 1, e = 2000000000000000000LL; s < e; ) {
			long long m = (s + e) / 2;
			if (query(m) > c) e = m;
			else s = m + 1;
		}
		r = s;
		for (s = 1, e = 2000000000000000000LL; s < e; ) {
			long long m = (s + e) / 2;
			if (query(m) < c) s = m + 1;
			else e = m;
		}
		l = s;
		printf("%I64d\n", r - l);
	}
	return 0;
}


#include <iostream>
#include <climits>
#include <cstdio>
#include <cstring>
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define MAX 10000
using namespace std;

int n, c, a[MAX], b[MAX];

inline long long muldiv(long long a, long long x, long long b) {
	return (a / b) * (x / b) * b +
		   (a / b) * (x % b) +
		   (a % b) * (x / b) +
		   ((a % b) * (x % b)) / b;
}

inline long long qry(long long x) {
	long long res = n;
	FOR (i, n) res += muldiv(a[i], x, b[i]);
	return res;
}

long long bsearch(bool right) {
	long long s = 0, e = 1000000000000000001LL;
	while (e - s > 1) {
		long long m = (s + e) / 2;
		long long q = qry(m);
		if (right) {
			if (q > c) e = m;
			else if (q == c) s = m;
			else s = m + 1;
		} else {
			if (q > c) e = m - 1;
			else if (q == c) e = m;
			else s = m;
		}
	}
	if (qry(right ? s : e) != c) return -1;
	return e;
}

int main() {
	bool notzero = false;
	scanf("%d%d", &n, &c);
	FOR (i, n) scanf("%d%d", &a[i], &b[i]), notzero |= a[i];

	if (!notzero) printf("%d\n", (c == n) ? -1 : 0);
	else {
		long long r = bsearch(true), l = bsearch(false);
		if (r >= 0 && l >= 0) printf("%I64d\n", r - l);
		else printf("0\n");
	}
	return 0;
}


#include <iostream>
#include <climits>
#include <cstdio>
#include <cstring>
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define MAX 10000
using namespace std;

int n, c, a[MAX], b[MAX];

inline long long muldiv(long long a, long long x, long long b) {
	return (a / b) * (x / b) * b +
		   (a / b) * (x % b) +
		   (a % b) * (x / b) +
		   ((a % b) * (x % b)) / b;
}

inline long long qry(long long x) {
	long long res = n;
	FOR (i, n) res += muldiv(a[i], x, b[i]);
	return res;
}

long long bsearch(bool right) {
	long long s = 1, e = 1000000000000000001LL;
	while (e - s > 1) {
		long long m = (s + e) / 2;
		long long q = qry(m);
		if (right) {
			if (q > c) e = m;
			else if (q == c) s = m;
			else s = m + 1;
		} else {
			if (q > c) e = m - 1;
			else if (q == c) e = m;
			else s = m;
		}
	}
	if (qry(right ? s : e) != c) return -1;
	return e;
}

int main() {
	bool notzero = false;
	scanf("%d%d", &n, &c);
	FOR (i, n) scanf("%d%d", &a[i], &b[i]), notzero |= a[i];

	if (!notzero) printf("%d\n", (c == n) ? -1 : 0);
	else {
		long long r = bsearch(true), l = bsearch(false);
		if (r >= 0 && l >= 0) printf("%I64d\n", r - l);
		else printf("0\n");
	}
	return 0;
}


#include <iostream>
#include <climits>
#include <cstdio>
#include <cstring>
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define MAX 10000
using namespace std;

int n, c, a[MAX], b[MAX];

long long bsearch(bool right) {
	long long s = 1, e = 1000000000000000001LL;
	while (e - s > 1) {
		long long m = (s + e) / 2;
		long long q = n;
		FOR (i, n) q += a[i] * m / b[i];
		if (right) {
			if (q > c) e = m;
			else if (q == c) s = m;
			else s = m + 1;
		} else {
			if (q > c) e = m - 1;
			else if (q == c) e = m;
			else s = m;
		}
	}
	return e;
}

int main() {
	bool notzero = false;
	scanf("%d%d", &n, &c);
	FOR (i, n) scanf("%d%d", &a[i], &b[i]), notzero |= a[i];

	if (!notzero) printf("%d\n", (c == n) ? -1 : 0);
	else printf("%I64d\n", bsearch(true) - bsearch(false));
	return 0;
}


#include <iostream>
#include <climits>
#include <cstdio>
#include <cstring>
#define FOR(i, n) for (int i = 0; i < (n); ++i)
#define MAX 10000
using namespace std;

int n, c, a[MAX], b[MAX];

inline long long qry(long long x) {
	long long res = n;
	FOR (i, n) res += a[i] * x / b[i];
	return res;
}

long long bsearch(bool right) {
	long long s = 1, e = 1000000000000000001LL;
	while (e - s > 1) {
		long long m = (s + e) / 2;
		long long q = qry(m);
		if (right) {
			if (q > c) e = m;
			else if (q == c) s = m;
			else s = m + 1;
		} else {
			if (q > c) e = m - 1;
			else if (q == c) e = m;
			else s = m;
		}
	}
	if (right) {
		if (qry(s) != c) return -1;
	} else {
		if (qry(e) != c) return -1;
	}
	return e;
}

int main() {
	bool notzero = false;
	scanf("%d%d", &n, &c);
	FOR (i, n) scanf("%d%d", &a[i], &b[i]), notzero |= a[i];

	if (!notzero) printf("%d\n", (c == n) ? -1 : 0);
	else {
		long long r = bsearch(true), l = bsearch(false);
		if (r >= 0 && l >= 0) printf("%I64d\n", r - l);
		else printf("0\n");
	}
	return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

typedef long long ll;

const int maxn = 10 * 1000 + 5;

int a[maxn], b[maxn];

int n;

ll func(ll x)
{
  ll res = 0;
  for (int i = 0; i < n; ++i) {
    res += 1LL + x * a[i] / (ll)b[i];
  }
  return res;
}

int bin_search(ll c)
{
  int l = 0, r = 1 << 30;
  while (l + 1 < r) {
    int x = (l + r) >> 1;
    if (func(x) < c) {
      l = x;
    }
    else {
      r = x;
    }
  }

  return l;
}

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

  int res = bin_search(c + 1) - bin_search(c);
  cout << res << '\n';

  return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

typedef long long ll;

const int maxn = 10 * 1000 + 5;

int a[maxn], b[maxn];

int n;

ll func(ll x)
{
  ll res = 0;
  for (int i = 0; i < n; ++i) {
    res += 1 + min(x * a[i], (ll)b[i]);
  }
  return res;
}

bool bin_search(ll c)
{
  int l = 0, r = 1 << 30;
  while (l + 1 < r) {
    int x = (l + r) >> 1;
    if (func(x) < c) {
      l = x;
    }
    else {
      r = x;
    }
  }

  return l;
}

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

  int res = bin_search(c + 1) - bin_search(c);
  cout << res << '\n';

  return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

typedef unsigned long long ll;

inline int len(ll x)
{
  int res = 0;
  while (x) {
    ++res;
    x /= 10;
  }
  return res;
}

const int maxn = 10 * 1000 + 5;

ll a[maxn], b[maxn];

int n;

ll func(ll x, ll c)
{
  ll res = 0;
  for (int i = 0; i < n; ++i) {

    if (!a[i]) {
      res += 1LL;
      continue;
    }

    if (a[i] && x > c * b[i] / a[i] + 3) {
      return 1LL << 60;
    }

    if (x * a[i] / b[i] + 1 > c) {
      return 1LL << 60;
    }

    res += 1LL + x * a[i] / b[i];

    if (res > c) {
      return 1LL << 60;
    }
  }
  return res;
}

ll bin_search(ll c, ll mx)
{
  ll l = 0, r = 1LL << 60;//mx + 1;
  while (l + 1 < r) {
    ll x = (l + r) >> 1;
    if (func(x, c) < c) {
      l = x;
    }
    else {
      r = x;
    }
  }

  return l;
}

int main()
{
  ll c;
  cin >> n >> c;

  ll ma = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
    ma = max(ma, a[i]);
  }
  ll mx = (1LL << 60) / ma + 5;

  ll res = bin_search(c + 1, mx) - bin_search(c, mx);
  cout << res << '\n';

  return 0;
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=10005;
const int mm=1005;
int n,k,m,t,c;
ll a[nm],b[nm];
bool check[nm];
int chop(ll x){
    ll res =n;
    int i;
    FOR(i,1,n){
        res+=(a[i]*x/b[i]);
    }
    if(res>c) return 1;
    else if(res==c) return 0;
    return -1;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,x,y,z,w;
    IND2(n,c);
    FOR(i,1,n)
        scanf("%I64d%I64d",&a[i],&b[i]);
    long long l=1,r=1000000000000000000ll,mid=(l+r)/2;
    ll cantren=0,canduoi=0;
    while(l+1<r){
        if(chop(mid)>0)r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    if(chop(r)==0)cantren=r;
    else if(chop(l)==0) cantren=l;
    l=1,r=1000000000000000000ll,mid=(l+r)/2;
    while(l+1<r){
        if(chop(mid)>=0)r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    if(chop(l)==0) canduoi=l;
    else if(chop(r)==0) canduoi = r;
    if(chop(1)>0){
        OUTD(0);
        return 0;
    }
    OUTL(cantren-canduoi+1);
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=10005;
const int mm=1005;
int n,k,m,t,c;
ll a[nm],b[nm];
bool check[nm];
int chop(ll x){
    ll res =n;
    int i;
    FOR(i,1,n){
        res+=(a[i]*x/b[i]);
    }
    if(res>c) return 1;
    else if(res==c) return 0;
    return -1;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,x,y,z,w;
    IND2(n,c);
    FOR(i,1,n)
        scanf("%I64d%I64d",&a[i],&b[i]);
    long long l=0,r=1000000000000000000ll,mid=(l+r)/2;
    ll cantren=0,canduoi=0;
    while(l+1<r){
        if(chop(mid)>0)r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    if(chop(r)==0)cantren=r;
    else if(chop(l)==0) cantren=l;
    l=0,r=1000000000000000000ll,mid=(l+r)/2;
    while(l+1<r){
        if(chop(mid)>=0)r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    if(chop(l)==0) canduoi=l;
    else if(chop(r)==0) canduoi = r;
    if(chop(0)>0){
        OUTD(-1);
        return 0;
    }
    OUTL(cantren-canduoi+1);
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=10005;
const int mm=1005;
int n,k,m,t,c;
ll a[nm],b[nm];
bool check[nm];
int chop(ll x){
    ll res =n;
    int i;
    FOR(i,1,n){
        res+=(a[i]*x/b[i]);
    }
    if(res>c) return 1;
    else if(res==c) return 0;
    return -1;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,x,y,z,w;
    IND2(n,c);
    FOR(i,1,n)
        scanf("%I64d%I64d",&a[i],&b[i]);
    long long l=1,r=1000000000000000000ll,mid=(l+r)/2;
    ll cantren=0,canduoi=0;
    while(l+1<r){
        if(chop(mid)>0)r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    if(chop(r)==0)cantren=r;
    else if(chop(l)==0) cantren=l;
    l=1,r=1000000000000000000ll,mid=(l+r)/2;
    while(l+1<r){
        if(chop(mid)>=0)r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    if(chop(l)==0) canduoi=l;
    else if(chop(r)==0) canduoi = r;
    if(chop(1)>0){
        OUTD(-1);
        return 0;
    }
    if(cantren==1000000000000000000ll){
        OUTD(-1);
        return 0;
    }
    OUTL(cantren-canduoi+1);
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=10005;
const int mm=1005;
int n,k,m,t,c;
ll a[nm],b[nm];
bool check[nm];
int chop(ll x){
    ll res =n;
    int i;
    FOR(i,1,n){
        res+=(a[i]*x/b[i]);
    }
    if(res>c) return 1;
    else if(res==c) return 0;
    return -1;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,x,y,z,w;
    IND2(n,c);
    FOR(i,1,n)
        scanf("%I64d%I64d",&a[i],&b[i]);
    long long l=1,r=1000000000ll,mid=(l+r)/2;
    ll cantren=0,canduoi=0;
    while(l+1<r){
        if(chop(mid)>0)r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    if(chop(r)==0)cantren=r;
    else if(chop(l)==0) cantren=l;
    l=1,r=1000000000ll,mid=(l+r)/2;
    while(l+1<r){
        if(chop(mid)>=0)r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    if(chop(l)==0) canduoi=l;
    else if(chop(r)==0) canduoi = r;
    if(chop(1)>0){
        OUTD(0);
        return 0;
    }
    OUTL(cantren-canduoi+1);
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOR2(i,a,b) for(i=a;i<b;i++)
#define IFOR(i,a,b) for(i=a;i>=b;i--)
#define IFOR2(i,a,b) for(i=a;i>b;i--)
#define IND(a) scanf("%d",&a)
#define IND2(a,b) scanf("%d%d",&a,&b)
#define IND3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define INL(a) scanf("%I64d",&a)
#define INS(s) scanf("%s",&s)
#define OUTD(a) printf("%d ",a)
#define OUTD2(a,b) printf("%d %d ",a,b)
#define OUTD3(a,b,c) printf("%d %d %d",a,b,c)
#define pb push_back
#define OUTL(a) printf("%I64d ",a)
#define ll long long
using namespace std;
const int nm=10005;
const int mm=1005;
int n,k,m,t,c;
ll a[nm],b[nm];
bool check[nm];
int chop(ll x){
    ll res =n;
    int i;
    FOR(i,1,n){
        res+=(a[i]*x/b[i]);
    }
    if(res>c) return 1;
    else if(res==c) return 0;
    return -1;
}
main(){
    #ifndef ONLINE_JUDGE
    freopen("inp.txt","r",stdin);
    #endif
    int i,j,x,y,z,w;
    IND2(n,c);
    FOR(i,1,n)
        scanf("%I64d%I64d",&a[i],&b[i]);
    long long l=1,r=1000000000ll,mid=(l+r)/2;
    ll cantren=0,canduoi=0;
    while(l+1<r){
        if(chop(mid)>0)r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    if(chop(r)==0)cantren=r;
    else if(chop(l)==0) cantren=l;
    l=1,r=1000000000ll,mid=(l+r)/2;
    while(l+1<r){
        if(chop(mid)>=0)r=mid;
        else l=mid;
        mid=(l+r)/2;
    }
    if(chop(l)==0) canduoi=l;
    else if(chop(r)==0) canduoi = r;
    if(cantren==0){
        OUTD(0);
        return 0;
    }
    OUTL(cantren-canduoi+1);
}


//
//  main.cpp
//  Training
//
//  Created by Mickel Harlov on 14/11/2018.
//  Copyright © 2018 Mickel Harlov. All rights reserved.
//

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <numeric>

static int gcd (int a, int b)
{
    return b ? gcd (b, a % b) : a;
}

int main(int argc, const char * argv[])
{
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; i ++)
        std::cin >> a[i];

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

    std::map<long double, int> map;
    for (int i = 0; i < n; i ++)
    {
        if (a[i] == 0)
        {
            if (b[i] == 0)
                map[0] ++;
        }
        else if (b[i] == 0)
            map[0] ++;
        else
        {
            long double r0 = a[i];
            long double r1 = b[i];

            map[-(r1/r0)] ++;
        }
    }

    int result = 0;
    for (auto it = map.begin(); it != map.end(); it ++)
    {
        if (it->first != 0)
            result = std::max(result, it->second + map[0]);
        else result = std::max(result, it->second);
    }
    std::cout << result << std::endl;

    return 0;
}


//
//  main.cpp
//  Training
//
//  Created by Mickel Harlov on 14/11/2018.
//  Copyright © 2018 Mickel Harlov. All rights reserved.
//

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <numeric>

static int gcd (int a, int b)
{
    return b ? gcd (b, a % b) : a;
}

int main(int argc, const char * argv[])
{
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; i ++)
        std::cin >> a[i];

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

    std::map<std::pair<int, int>, int> map;
    for (int i = 0; i < n; i ++)
    {
        if (a[i] == 0)
        {
            if (b[i] == 0)
                map[{ 0, 0 }] ++;
        }
        else
        {
            int d = gcd(a[i], b[i]);
            a[i] /= d; b[i] /= d;

            map[{ b[i], a[i] }] ++;
        }
    }

    int result = 0;
    for (auto it = map.begin(); it != map.end(); it ++)
        result = std::max(result, it->second);

    std::cout << result << std::endl;

    return 0;
}


//
//  main.cpp
//  Training
//
//  Created by Mickel Harlov on 14/11/2018.
//  Copyright © 2018 Mickel Harlov. All rights reserved.
//

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <numeric>

static int gcd (int a, int b)
{
    return b ? gcd (b, a % b) : a;
}

int main(int argc, const char * argv[])
{
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; i ++)
        std::cin >> a[i];

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

    std::map<long double, int> map;
    for (int i = 0; i < n; i ++)
    {
        if (a[i] == 0)
        {
            if (b[i] == 0)
                map[0] ++;
        }
        else if (b[i] == 0)
            map[0] ++;
        else
        {
            long double r0 = a[i];
            long double r1 = b[i];

            map[-(r1/r0)] ++;
        }
    }

    int result = 0;
    for (auto it = map.begin(); it != map.end(); it ++)
        result = std::max(result, it->second);

    std::cout << result << std::endl;

    return 0;
}


//
//  main.cpp
//  Training
//
//  Created by Mickel Harlov on 14/11/2018.
//  Copyright © 2018 Mickel Harlov. All rights reserved.
//

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <numeric>

static int gcd (int a, int b)
{
    return b ? gcd (b, a % b) : a;
}

int main(int argc, const char * argv[])
{
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; i ++)
        std::cin >> a[i];

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

    std::map<std::pair<int, int>, int> map;
    for (int i = 0; i < n; i ++)
    {
        if (a[i] == 0)
        {
            if (b[i] == 0)
                map[{ 0, 0 }] ++;
        }
        else
        {
            int d = gcd(a[i], b[i]);
            a[i] /= d; b[i] /= d;

            map[{ -b[i], a[i] }] ++;
        }
    }

    int result = 0;
    for (auto it = map.begin(); it != map.end(); it ++)
        result = std::max(result, it->second);

    std::cout << result << std::endl;

    return 0;
}


//
//  main.cpp
//  Training
//
//  Created by Mickel Harlov on 14/11/2018.
//  Copyright © 2018 Mickel Harlov. All rights reserved.
//

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <numeric>

static int gcd (int a, int b)
{
    return b ? gcd (b, a % b) : a;
}

int main(int argc, const char * argv[])
{
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; i ++)
        std::cin >> a[i];

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

    std::map<long double, int> map;
    for (int i = 0; i < n; i ++)
    {
        if (a[i] == 0)
        {
            if (b[i] == 0)
                map[0] ++;
        }
        else if (b[i] == 0)
            map[0] ++;
        else
        {
            long double r0 = a[i];
            long double r1 = b[i];

            map[-(r1/r0)] ++;
        }
    }

    int result = 0;
    for (auto it = map.begin(); it != map.end(); it ++)
    {
        if (it->second != 0)
            result = std::max(result, it->second + map[0]);
        else result = std::max(result, it->second);
    }
    std::cout << result << std::endl;

    return 0;
}


//
//  main.cpp
//  Training
//
//  Created by Mickel Harlov on 14/11/2018.
//  Copyright © 2018 Mickel Harlov. All rights reserved.
//

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <numeric>

static int gcd (int a, int b)
{
    return b ? gcd (b, a % b) : a;
}

int main(int argc, const char * argv[])
{
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; i ++)
        std::cin >> a[i];

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

    std::map<std::pair<int, int>, int> map;
    for (int i = 0; i < n; i ++)
    {
        if (a[i] == 0)
        {
            if (b[i] == 0)
                map[{ 0, 0 }] ++;
        }
        else
        {
            int d = std::abs(gcd(a[i], b[i]));
            a[i] /= d; b[i] /= d;

            if (a[i] < 0)
                map[{ b[i], -a[i] }] ++;
            else map[{ -b[i], a[i] }] ++;
        }
    }

    int result = 0;
    for (auto it = map.begin(); it != map.end(); it ++)
        result = std::max(result, it->second);

    std::cout << result << std::endl;

    return 0;
}


//
//  main.cpp
//  Training
//
//  Created by Mickel Harlov on 14/11/2018.
//  Copyright © 2018 Mickel Harlov. All rights reserved.
//

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <numeric>

static int gcd (int a, int b)
{
    return b ? gcd (b, a % b) : a;
}

int main(int argc, const char * argv[])
{
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; i ++)
        std::cin >> a[i];

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

    std::map<std::pair<int, int>, int> map;
    for (int i = 0; i < n; i ++)
    {
        if (a[i] == 0)
        {
            if (b[i] == 0)
                map[{ 0, 0 }] ++;
        }
        else
        {
            int d = gcd(a[i], b[i]);
            a[i] /= d; b[i] /= d;

            map[{ a[i], b[i] }] ++;
        }
    }

    int result = 0;
    for (auto it = map.begin(); it != map.end(); it ++)
        result = std::max(result, it->second);

    std::cout << result << std::endl;

    return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 3e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int a[N], b[N], z;
struct Node {
	int fz, fm;
	Node() {}
	Node(rg int fz, rg int fm) :fz(fz), fm(fm) {}
	bool operator <(const rg Node &s)const { return fm < s.fm || (fm == s.fm&&fz < s.fz); }
}p[N];
inl int GCD(rg int a, rg int b) { while (b ^= a ^= b ^= a %= b); return a; }

int main(void)
{
	rg int n = fast_IO::read(), ans = 0;
	for (rg int i = 1; i <= n; ++i)a[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)b[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)
	{
		if (a[i])
		{
			rg int gcd = GCD(abs(b[i]), abs(a[i]));
			if (!b[i])gcd = 1;
			p[i].fz = abs(b[i]) / gcd; p[i].fm = abs(a[i]) / gcd;
			if ((-b[i] < 0) ^ (a[i] < 0))p[i].fz *= -1;
		}
		else z += !b[i];
	}
	sort(p + 1, p + n + 1);
	for (rg int i = 1, j; i <= n; i = j)
	{
		if (!a[i]) { j = i + 1; continue; }
		rg int tot = 0; j = i;
		while (j <= n && p[i].fz == p[j].fz&&p[i].fm == p[j].fm)++j, ++tot;
		ans = fast_IO::max(ans, tot);
	}
	fast_IO::write(ans + z);
	return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 3e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int a[N], b[N], z;
struct Node {
	int fz, fm;
	Node() {}
	Node(rg int fz, rg int fm) :fz(fz), fm(fm) {}
	bool operator <(const rg Node &s)const { return fm < s.fm || (fm == s.fm&&fz < s.fz); }
}p[N];
inl int GCD(rg int a, rg int b) { while (b ^= a ^= b ^= a %= b); return a; }

int main(void)
{
	rg int n = fast_IO::read(), ans = 0;
	for (rg int i = 1; i <= n; ++i)a[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)b[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)
	{
		if (a[i])
		{
			rg int gcd = GCD(b[i], a[i]);
			p[i].fz = -b[i] / gcd; p[i].fm = a[i] / gcd;
		}
		else z += !b[i];
	}
	sort(p + 1, p + n + 1);
	for (rg int i = 1, j; i <= n; i = j)
	{
		if (!a[i]) { j = i + 1; continue; }
		rg int tot = 0; j = i;
		while (j <= n && p[i].fz == p[j].fz&&p[i].fm == p[j].fm)++j, ++tot;
		ans = fast_IO::max(ans, tot);
	}
	fast_IO::write(ans + z);
	return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 3e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int a[N], b[N], z;
struct Node {
	int fz, fm;
	Node() {}
	Node(rg int fz, rg int fm) :fz(fz), fm(fm) {}
	bool operator <(const rg Node &s)const { return fm < s.fm || (fm == s.fm&&fz < s.fz); }
}p[N];
inl int GCD(rg int a, rg int b) { while (b ^= a ^= b ^= a %= b); return a; }

int main(void)
{
	rg int n = fast_IO::read(), ans = 0;
	for (rg int i = 1; i <= n; ++i)a[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)b[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)
	{
		if (a[i])
		{
			rg int gcd = GCD(abs(b[i]), abs(a[i]));
			p[i].fz = abs(b[i]) / gcd; p[i].fm = abs(a[i]) / gcd;
			if (-b[i] < 0 ^ a[i] < 0)p[i].fz *= -1;
		}
		else z += !b[i];
	}
	sort(p + 1, p + n + 1);
	for (rg int i = 1, j; i <= n; i = j)
	{
		if (!a[i]) { j = i + 1; continue; }
		rg int tot = 0; j = i;
		while (j <= n && p[i].fz == p[j].fz&&p[i].fm == p[j].fm)++j, ++tot;
		ans = fast_IO::max(ans, tot);
	}
	fast_IO::write(ans + z);
	return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 3e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int a[N], b[N], z;
map<long double, int>mp;

int main(void)
{
	rg int n = fast_IO::read(), ans = 0;
	for (rg int i = 1; i <= n; ++i)a[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)b[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)
	{
		if (a[i])ans = fast_IO::max(ans, ++mp[(long double)-b[i] / a[i]]);
		else z += !b[i];
	}
	fast_IO::write(fast_IO::max(ans,z));
	return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 3e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int a[N], b[N], z;
struct Node {
	int fz, fm;
	Node() {}
	Node(rg int fz, rg int fm) :fz(fz), fm(fm) {}
	bool operator <(const rg Node &s)const { return fm < s.fm || (fm == s.fm&&fz < s.fz); }
}p[N];
inl int GCD(rg int a, rg int b) { while (b ^= a ^= b ^= a %= b); return a; }

int main(void)
{
	rg int n = fast_IO::read(), ans = 0;
	for (rg int i = 1; i <= n; ++i)a[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)b[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)
	{
		if (a[i])
		{
			rg int gcd = GCD(-b[i], a[i]);
			p[i].fz = -b[i] / gcd; p[i].fm = a[i] / gcd;
		}
		else z += !b[i];
	}
	sort(p + 1, p + n + 1);
	for (rg int i = 1, j; i <= n; i = j)
	{
		if (!a[i]) { j = i + 1; continue; }
		rg int tot = 0; j = i;
		while (j <= n && p[i].fz == p[j].fz&&p[i].fm == p[j].fm)++j, ++tot;
		ans = fast_IO::max(ans, tot);
	}
	fast_IO::write(ans + z);
	return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 3e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int a[N], b[N], z;
struct Node {
	int fz, fm;
	Node() {}
	Node(rg int fz, rg int fm) :fz(fz), fm(fm) {}
	bool operator <(const rg Node &s)const { return fm < s.fm || (fm == s.fm&&fz < s.fz); }
}p[N];
inl int GCD(rg int a, rg int b) { while (b ^= a ^= b ^= a %= b); return a; }

int main(void)
{
	rg int n = fast_IO::read(), ans = 0;
	for (rg int i = 1; i <= n; ++i)a[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)b[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)
	{
		if (a[i])
		{
			rg int gcd = GCD(abs(b[i]), abs(a[i]));
			p[i].fz = abs(b[i]) / gcd; p[i].fm = abs(a[i]) / gcd;
			if ((-b[i] < 0) ^ (a[i] < 0))p[i].fz *= -1;
		}
		else z += !b[i];
	}
	sort(p + 1, p + n + 1);
	for (rg int i = 1, j; i <= n; i = j)
	{
		if (!a[i]) { j = i + 1; continue; }
		rg int tot = 0; j = i;
		while (j <= n && p[i].fz == p[j].fz&&p[i].fm == p[j].fm)++j, ++tot;
		ans = fast_IO::max(ans, tot);
	}
	fast_IO::write(ans + z);
	return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 3e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int a[N], b[N], z;
map<long double, int>mp;

int main(void)
{
	rg int n = fast_IO::read(), ans = 0;
	for (rg int i = 1; i <= n; ++i)a[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)b[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)
	{
		if (a[i])ans = fast_IO::max(ans, ++mp[(long double)-b[i] / a[i]]);
		else z += !b[i];
	}
	fast_IO::write(ans + z);
	return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 3e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int a[N], b[N], z;
struct Node {
	int fz, fm;
	Node() {}
	Node(rg int fz, rg int fm) :fz(fz), fm(fm) {}
	bool operator <(const rg Node &s)const { return fm < s.fm || (fm == s.fm&&fz < s.fz); }
}p[N];
inl int GCD(rg int a, rg int b) { while (b ^= a ^= b ^= a %= b); return a; }

int main(void)
{
	rg int n = fast_IO::read(), ans = 0;
	for (rg int i = 1; i <= n; ++i)a[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)b[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)
	{
		if (a[i])
		{
			rg int gcd = GCD(abs(b[i]), abs(a[i]));
			p[i].fz = b[i] / gcd; p[i].fm = a[i] / gcd;
			if (b[i] < 0 ^ a[i] < 0)p[i].fz *= -1;
		}
		else z += !b[i];
	}
	sort(p + 1, p + n + 1);
	for (rg int i = 1, j; i <= n; i = j)
	{
		if (!a[i]) { j = i + 1; continue; }
		rg int tot = 0; j = i;
		while (j <= n && p[i].fz == p[j].fz&&p[i].fm == p[j].fm)++j, ++tot;
		ans = fast_IO::max(ans, tot);
	}
	fast_IO::write(ans + z);
	return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 3e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int a[N], b[N], z;
struct Node {
	int fz, fm;
	Node() {}
	Node(rg int fz, rg int fm) :fz(fz), fm(fm) {}
	bool operator <(const rg Node &s)const { return fm < s.fm || (fm == s.fm&&fz < s.fz); }
}p[N];
inl int GCD(rg int a, rg int b) { while (b ^= a ^= b ^= a %= b); return a; }

int main(void)
{
	rg int n = fast_IO::read(), ans = 0;
	for (rg int i = 1; i <= n; ++i)a[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)b[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)
	{
		if (a[i])
		{
			rg int gcd = GCD(b[i], a[i]);
			p[i].fz = -b[i] / gcd; p[i].fm = a[i] / gcd;
		}
		else z += !b[i];
	}
	sort(p + 1, p + n + 1);
	for (rg int i = 1, j; i <= n; i = j)
	{
		if (!a[i]) { j = i + 1; continue; }
		rg int tot = 0; j = i;
		while (j <= n && p[i].fz == p[j].fz&&p[i].fm == p[j].fm)++j, ++tot;
		ans = fast_IO::max(ans, tot);
	}
	fast_IO::write(fast_IO::max(ans, z));
	return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) (x&-x)
#define jh(x, y) x^=y^=x^=y
#define rg register
#define inl inline
typedef long long ll;
const int N = 3e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
using namespace std;
namespace fast_IO {
	inl ll read() {
		rg char c;
		rg ll x = 0;
		rg bool flag = false;
		while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
		if (c == EOF)return c; if (c == '-')flag = true; else x = c ^ 48;
		while ((c = getchar()) != ' ' && c != '\n' && c != '\r'&&~c)
			x = (x << 1) + (x << 3) + (c ^ 48);
		if (flag)return -x; return x;
	}
	inl ll max(rg ll a, rg ll b) { if (a > b)return a; return b; }
	inl ll min(rg ll a, rg ll b) { if (a < b)return a; return b; }
	void write(rg ll x) { if (x < 0)putchar('-'), x = -x; if (x >= 10)write(x / 10); putchar(x % 10 ^ 48); }
}
int a[N], b[N], z;
struct Node {
	int fz, fm;
	Node() {}
	Node(rg int fz, rg int fm) :fz(fz), fm(fm) {}
	bool operator <(const rg Node &s)const { return fm < s.fm || (fm == s.fm&&fz < s.fz); }
}p[N];
inl int GCD(rg int a, rg int b) { while (b ^= a ^= b ^= a %= b); return a; }

int main(void)
{
	rg int n = fast_IO::read(), ans = 0;
	for (rg int i = 1; i <= n; ++i)a[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)b[i] = fast_IO::read();
	for (rg int i = 1; i <= n; ++i)
	{
		if (a[i])
		{
			rg int gcd = GCD(abs(b[i]), abs(a[i]));
			p[i].fz = b[i] / gcd; p[i].fm = a[i] / gcd;
			if (-b[i] < 0 ^ a[i] < 0)p[i].fz *= -1;
		}
		else z += !b[i];
	}
	sort(p + 1, p + n + 1);
	for (rg int i = 1, j; i <= n; i = j)
	{
		if (!a[i]) { j = i + 1; continue; }
		rg int tot = 0; j = i;
		while (j <= n && p[i].fz == p[j].fz&&p[i].fm == p[j].fm)++j, ++tot;
		ans = fast_IO::max(ans, tot);
	}
	fast_IO::write(ans + z);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<list>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<tuple>
#include<functional>
#include<utility>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cassert>
#define y1 fuck
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long;
using ull = unsigned long long;
using dbl = double;
using ldb = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using mii = map<int,int>;
using msi = map<string,int>;
using umii = unordered_map<int,int>;
using umsi = unordered_map<string,int>;
using iii = tuple<int,int,int>;
using lll = tuple<ll,ll,ll>;
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {if(!a||!b)return a+b;return a*(b/gcd(a,b));}
const int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

int n;
pll a[222222];

int main() {
    //cin.tie(0); ios_base::sync_with_stdio(0);

    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i].snd);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i].fst);
        if (a[i].fst == 0 || a[i].snd == 0) {
            continue;
        }
        int gc = gcd(a[i].fst, a[i].snd);
        a[i].fst /= gc;
        a[i].snd /= gc;
    }

    sort(a+1,a+1+n);

    ll ans = 0;

    ll cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i].fst == 0) {
            cnt++;
        }
    }
    ans = cnt;

    a[n+1].fst = 2e9;
    a[n+1].snd = 2e9;

    int j = 1;
    for (int i = 1; i <= n; i++) {
        j = i+1;
        while (j <= n && a[i].fst == a[j].fst && a[i].snd == a[j].snd) {
            j++;
        }
        if (a[i].snd == 0) {
            continue;
        }
        ans = max(ans, (ll)j-i);
        i = j;
    }

    cnt=0;
    for (int i = 1; i <= n; i++) {
        if (a[i].fst+a[i].snd == 0) {
            cnt++;
        }
    }
    ans = max(ans, (ll)cnt);
    for (int i = 1; i <= n; i++) {
        if (a[i].snd-a[i].fst == 0) {
            cnt++;
        }
    }
    ans = max(ans, (ll)cnt);

    printf("%lld", ans);

    return 0;
}