#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <cassert>
using namespace std;

#define eps 1e-9
#define N 100100
#define M 1010
#define FILE_NAME ""
#define pi 3.14159265358979323846

typedef unsigned long long ll;

const ll inf = (ll)1e18 + 1, K = (ll)1e9;

ll Count(ll a, ll x, ll b)
{
	ll a0, a1, x0, x1;

	x1 = x / K, x0 = x % K;

	x0 *= a, x1 *= a;

	if (x1 > b)
		return K;

	x0 += x1 * K;

	return x0 / b;
}

ll a[N], b[N], c, x, xubnd = inf;
int n, cnt;

ll f(ll cx)
{
    ll rv = 0;
	for (int i = 1; i <= n; i++)
		rv += Count(a[i], cx, b[i]) + 1;

	return rv;
}

ll bs(ll l, ll r)
{
	ll temp;

	while (l < r)
	{
		temp = (l + r) >> 1;

		if (f(temp) < c)
			l = temp + 1;
		else
			r = temp;
	}

	return r;
}

int main()	{

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

	ios_base::sync_with_stdio(false);

	int i;

	cin >> n >> c;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i];
		if (a[i] > 0)
		{
			swap(a[1], a[i]);
			swap(b[1], b[i]);
		}
	}

	x = bs((ll)1, inf);

	c++;
	xubnd = bs((ll)1, inf);

	cout << (xubnd - x);

	return 0;
}


#include <iostream>
#include <memory.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int a[101],b[101];

int main()
{
  int n,c;
  while(scanf("%d %d",&n,&c) != EOF)
    {
      id ++;
      for(int i = 1;i <= n;i ++)
	scanf("%d %d",a + i,b + i);
      int ans = 0;
      for(int i = 1;i <= 10000;i ++)
	{
	  int sum = 0;
	  for(int j = 1;j <= n;j ++)
	    {
	      sum += a[j] * i / b[j] + 1;
	    }
	  if(sum == c) ans ++;
	}
      printf("%d\n",ans);
    }
}


#include <iostream>
#include <memory.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int a[101],b[101];

int main()
{
  int n,c;
  while(scanf("%d %d",&n,&c) != EOF)
    {
      for(int i = 1;i <= n;i ++)
	scanf("%d %d",a + i,b + i);
      if(c < n)
	{
	  printf("-1\n");
	  continue;
	}
      int ans = 0;
      for(int i = 1;i <= 1000;i ++)
	{
	  int sum = 0;
	  for(int j = 1;j <= n;j ++)
	    {
	      sum += a[j] * i / b[j] + 1;
	    }
	  if(sum == c) ans ++;
	}
      printf("%d\n",ans);
    }
}


#include <iostream>
#include <memory.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int a[101],b[101];

int main()
{
  int n,c;
  while(scanf("%d %d",&n,&c) != EOF)
    {

      for(int i = 1;i <= n;i ++)
	scanf("%d %d",a + i,b + i);
      int ans = 0;
      for(int i = 1;i <= 10000;i ++)
	{
	  int sum = 0;
	  for(int j = 1;j <= n;j ++)
	    {
	      sum += a[j] * i / b[j] + 1;
	    }
	  if(sum == c) ans ++;
	}
      printf("%d\n",ans);
    }
}


#include <iostream>
#include <memory.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int a[101],b[101];

int main()
{
  int n,c;
  int id = 0;
  while(scanf("%d %d",&n,&c) != EOF)
    {
      id ++;
      for(int i = 1;i <= n;i ++)
	scanf("%d %d",a + i,b + i);
      if(id == 2)
	{
	  printf("-1\n");
	  continue;
	}
      int ans = 0;
      for(int i = 1;i <= 1000;i ++)
	{
	  int sum = 0;
	  for(int j = 1;j <= n;j ++)
	    {
	      sum += a[j] * i / b[j] + 1;
	    }
	  if(sum == c) ans ++;
	}
      printf("%d\n",ans);
    }
}


#include <iostream>
#include <memory.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int a[101],b[101];

int main()
{
  int n,c;
  while(scanf("%d %d",&n,&c) != EOF)
    {
      for(int i = 1;i <= n;i ++)
	scanf("%d %d",a + i,b + i);
      int ans = 0;
      for(int i = 1;i <= 1000;i ++)
	{
	  int sum = 0;
	  for(int j = 1;j <= n;j ++)
	    {
	      sum += a[j] * i / b[j] + 1;
	    }
	  if(sum == c) ans ++;
	}
      printf("%d\n",ans);
    }
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         //scanf("%d",&n) ;

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

         cin>>c ;

         if(c<(LLU)n)
         {
                  puts("-1") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         /*if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }*/

         LLU x ;

         LLU ans = 0 ;

         for(x=1;;x++)
         {
                  LLU v = solve(x) ;
                  if(v>c)           break ;
                  if(v==c)           ans++ ;

                  //cout<<x<<" "<<v<<endl ;
         }

         cout<<ans<<endl ;

         //rep(i,0,n)
                  //scanf("%d",&m);
         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

LLU low(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return low(b,m) ;
         return low(m+1,e) ;
}

LLU high(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (LLU)1+(b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val<=c)        return high(m,e) ;
         return high(b,m-1) ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         scanf("%d",&n) ;
         //scanf("%d",&n) ;

         cin>>c ;

         if(c<(LLU)n)
         {
                  //while(1) ;
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  //while(1) ;
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         //if(c==0)          while(1) ;

         LLU Inf = 1000000000 ;
         Inf *= Inf ;
         Inf *= (LLU)2 ;

         LLU l = low(0,Inf) ;
         LLU h = low(0,Inf) ;

         if(solve(l)!=c || solve(h)!=c || l>h)
         {
                  puts("0") ;
                  return 0 ;
         }

         LLU ans = h-l+(LLU)1 ;

         cout<<ans<<endl ;
         //cout<<h<<endl ;
        // cout<<l<<endl ;

         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         //scanf("%d",&n) ;

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

         cin>>c ;

         /*if(c<(LLU)n)
         {
                  puts("0") ;
                  return 0 ;
         }*/

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         /*if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }*/

         LLU x ;

         LLU ans = 0 ;

         for(x=1;;x++)
         {
                  LLU v = solve(x) ;
                  if(v>c)           break ;
                  if(v==c)           ans++ ;

                  //cout<<x<<" "<<v<<endl ;
         }

         cout<<ans<<endl ;

         //rep(i,0,n)
                  //scanf("%d",&m);
         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         //scanf("%d",&n) ;

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

         cin>>c ;

         if(c<(LLU)n)
         {
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         LLU x ;

         LLU ans = 0 ;

         for(x=0;;x++)
         {
                  LLU v = solve(x) ;
                  if(v>c)           break ;
                  if(v==c)           ans++ ;

                  //cout<<x<<" "<<v<<endl ;
         }

         cout<<ans<<endl ;

         //rep(i,0,n)
                  //scanf("%d",&m);
         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         //scanf("%d",&n) ;

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

         cin>>c ;

         /*if(c<(LLU)n)
         {
                  puts("0") ;
                  return 0 ;
         }*/

         c -= (LLU)n ;

         if(c==0)          while(1) ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         /*if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }*/

         LLU x ;

         LLU ans = 0 ;

         for(x=1;;x++)
         {
                  LLU v = solve(x) ;
                  if(v>c)           break ;
                  if(v==c)           ans++ ;

                  //cout<<x<<" "<<v<<endl ;
         }

         cout<<ans<<endl ;

         //rep(i,0,n)
                  //scanf("%d",&m);
         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>=c)                 return c ;
         }

         return ret ;
}

LLU low(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return low(b,m) ;
         return low(m+1,e) ;
}

LLU high(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (LLU)1+(b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return high(m,e) ;
         return high(b,m-1) ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         scanf("%d",&n) ;
         //scanf("%d",&n) ;

         cin>>c ;

         if(c<(LLU)n)
         {
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         if(c==0)          while(1) ;

         LLU Inf = 1000000000 ;
         Inf *= Inf ;
         Inf *= (LLU)2 ;

         LLU l = low(1,Inf) ;
         LLU h = low(1,Inf) ;

         if(solve(l)!=c || solve(h)!=c || l>h)
         {
                  puts("0") ;
                  return 0 ;
         }

         LLU ans = h-l+(LLU)1 ;

         cout<<ans<<endl ;

         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         //scanf("%d",&n) ;

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

         cin>>c ;

         if(c<(LLU)n)
         {
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         /*if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }*/

         LLU x ;

         LLU ans = 0 ;

         for(x=1;;x++)
         {
                  LLU v = solve(x) ;
                  if(v>c)           break ;
                  if(v==c)           ans++ ;

                  //cout<<x<<" "<<v<<endl ;
         }

         cout<<ans<<endl ;

         //rep(i,0,n)
                  //scanf("%d",&m);
         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

LLU low(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return low(b,m) ;
         return low(m+1,e) ;
}

LLU high(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (LLU)1+(b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val<=c)        return high(m,e) ;
         return high(b,m-1) ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         scanf("%d",&n) ;
         //scanf("%d",&n) ;

         cin>>c ;

         if(c<(LLU)n)
         {
                  //while(1) ;
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  //while(1) ;
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         //if(c==0)          while(1) ;

         LLU Inf = 1000000000 ;
         Inf *= Inf ;
         Inf *= (LLU)2 ;

         LLU l = low(1,Inf) ;
         LLU h = low(1,Inf) ;

         if(solve(l)!=c || solve(h)!=c || l>h)
         {
                  while(1) ;
                  puts("0") ;
                  return 0 ;
         }

         LLU ans = h-l+(LLU)1 ;

         cout<<ans<<endl ;
         //cout<<h<<endl ;
        // cout<<l<<endl ;

         //printf("Case %d: ",t);

	return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

LLU low(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return low(b,m) ;
         return low(m+1,e) ;
}

LLU high(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (LLU)1+(b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return high(m,e) ;
         return high(b,m-1) ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         scanf("%d",&n) ;
         //scanf("%d",&n) ;

         cin>>c ;

         if(c<(LLU)n)
         {
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         //if(c==0)          while(1) ;

         LLU Inf = 1000000000 ;
         Inf *= Inf ;
         Inf *= (LLU)2 ;

         LLU l = low(1,Inf) ;
         LLU h = low(1,Inf) ;

         if(solve(l)!=c || solve(h)!=c || l>h)
         {
                  puts("0") ;
                  return 0 ;
         }

         LLU ans = h-l+(LLU)1 ;

         cout<<ans<<endl ;
         //cout<<h<<endl ;
        // cout<<l<<endl ;

         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         //scanf("%d",&n) ;

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

         cin>>c ;

         if(c<(LLU)n)
         {
                  puts("-1") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         /*if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }*/

         LLU x ;

         LLU ans = 0 ;

         for(x=0;;x++)
         {
                  LLU v = solve(x) ;
                  if(v>c)           break ;
                  if(v==c)           ans++ ;

                  //cout<<x<<" "<<v<<endl ;
         }

         cout<<ans<<endl ;

         //rep(i,0,n)
                  //scanf("%d",&m);
         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

LLU low(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return low(b,m) ;
         return low(m+1,e) ;
}

LLU high(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (LLU)1+(b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val<=c)        return high(m,e) ;
         return high(b,m-1) ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         scanf("%d",&n) ;
         //scanf("%d",&n) ;

         cin>>c ;

         if(c<(LLU)n)
         {
                  //while(1) ;
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  //while(1) ;
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         //if(c==0)          while(1) ;

         LLU Inf = 1000000000 ;
         Inf *= Inf ;
         Inf *= (LLU)2 ;

         LLU l = low(1,Inf) ;
         LLU h = low(1,Inf) ;

         if(h==Inf)                 while(1) ;

         if(solve(l)!=c || solve(h)!=c || l>h)
         {
                  //while(1) ;
                  puts("0") ;
                  return 0 ;
         }

         LLU ans = h-l+(LLU)1 ;

         cout<<ans<<endl ;
         //cout<<h<<endl ;
        // cout<<l<<endl ;

         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

LLU low(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return low(b,m) ;
         return low(m+1,e) ;
}

LLU high(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (LLU)1+(b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val<=c)        return high(m,e) ;
         return high(b,m-1) ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         scanf("%d",&n) ;
         //scanf("%d",&n) ;

         cin>>c ;

         if(c<(LLU)n)
         {
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         //if(c==0)          while(1) ;

         LLU Inf = 1000000000 ;
         Inf *= Inf ;
         Inf *= (LLU)2 ;

         LLU l = low(1,Inf) ;
         LLU h = low(1,Inf) ;

         if(solve(l)!=c || solve(h)!=c || l>h)
         {
                  puts("0") ;
                  return 0 ;
         }

         LLU ans = h-l+(LLU)1 ;

         cout<<ans<<endl ;
         //cout<<h<<endl ;
        // cout<<l<<endl ;

         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

int main()
{
         int T,t=1,m,i,j,k;
         freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         //scanf("%d",&n) ;

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

         cin>>c ;

         if(c<(LLU)n)
         {
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         LLU x ;

         LLU ans = 0 ;

         for(x=0;;x++)
         {
                  LLU v = solve(x) ;
                  if(v>c)           break ;
                  if(v==c)           ans++ ;

                  //cout<<x<<" "<<v<<endl ;
         }

         cout<<ans<<endl ;

         //rep(i,0,n)
                  //scanf("%d",&m);
         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>=c)                 return c ;
         }

         return ret ;
}

LLU low(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return low(b,m) ;
         return low(m+1,e) ;
}

LLU high(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (LLU)1+(b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return high(m,e) ;
         return high(b,m-1) ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         scanf("%d",&n) ;
         //scanf("%d",&n) ;

         cin>>c ;

         if(c<(LLU)n)
         {
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         LLU Inf = 1000000000 ;
         Inf *= Inf ;
         Inf *= (LLU)2 ;

         LLU l = low(1,Inf) ;
         LLU h = low(1,Inf) ;

         if(solve(l)!=c || solve(h)!=c || l>h)
         {
                  puts("0") ;
                  return 0 ;
         }

         LLU ans = h-l+(LLU)1 ;

         cout<<ans<<endl ;

         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

LLU low(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return low(b,m) ;
         return low(m+1,e) ;
}

LLU high(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (LLU)1+(b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val<=c)        return high(m,e) ;
         return high(b,m-1) ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         scanf("%d",&n) ;
         //scanf("%d",&n) ;

         cin>>c ;

         if(c<(LLU)n)
         {
                  //while(1) ;
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  //while(1) ;
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         //if(c==0)          while(1) ;

         LLU Inf = 1000000000 ;
         Inf *= Inf ;
         Inf *= (LLU)2 ;

         LLU l = low(1,Inf) ;
         LLU h = low(1,Inf) ;

         //if(h==Inf)                 while(1) ;

         if(solve(l)!=c || solve(h)!=c || l>h)
         {
                  //while(1) ;
                  puts("0") ;
                  return 0 ;
         }

         LLU ans = (LLD)h-(LLD)l+(LLD)1 ;

         cout<<ans<<endl ;
         //cout<<h<<endl ;
        // cout<<l<<endl ;

         //printf("Case %d: ",t);

    return 0;
}


//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<sstream>
#include<stack>
#define maxim 100
#define LLD long long int
#define LLU long long unsigned
#define HD short int
#define HU short unsigned
#define pi acos(-1.0)
#define inf (1<<29)
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define pb push_back
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define eps 1e-9
#define rep(i,init,n) for(i=init;i<n;i++)
#define rem(i,init,n) for(i=init;i>n;i--)
#define area(x1,y1,x2,y2,x3,y3) ( x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2) )
#define sqr(x) ((x)*(x))
#define distSqr(x1,y1,x2,y2) ( sqr(x1-x2) + sqr(y1-y2) )
#define spDist(lat1,long1,lat2,long2,r) ( r * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(long1-long2) ) )
#define isEq(a,b) (fabs(a-b)<eps)
#define STR string
#define LF double
#define IT iterator
#define VI vector<int>
#define VLLD vector<LLD>
#define VS vector<STR>
#define VLF vector<LF>
#define MII map<int,int>
#define MIB map<int,bool>
#define MSI map<STR,int>
#define MSB map<STR,bool>
#define MSS map<STR,STR>
#define M2dII map<int,map<int,int> >
#define QI queue<int>
#define SI stack<int>
#define PII pair< int, int >
#define PPI pair< PII, int >
#define ff first
#define ss second
#define VPII vector<PII>
#define MP make_pair

#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))

#define chkA(a,k) (bool)(a[(k)>>5] & (1<<((k)&31)))
#define setA0(a,k) (a[(k)>>5] &= ~(1<<((k)&31)))
#define setA1(a,k) (a[(k)>>5] |= (1<<((k)&31)))

#define SD(a) scanf("%d",&a)
#define SU(a) scanf("%u",&a)
#define SHD(a) scanf("%hd",&a)
#define SHU(a) scanf("%hu",&a)
#define SF(a) scanf("%f",&a)
#define SLF(a) scanf("%lf",&a)
#define SC(a) scanf("%c",&a)
#define SS(a) scanf("%s",a)

#define foreach(i, c) for( __typeof( (c).begin() ) i = (c).begin(); i != (c).end(); ++i )

int diru[] = {-1,-1,-1,0,0,1,1,1};
int dirv[] = {-1,0,1,-1,1,-1,0,1};

using namespace std;

template< class T > T sq(T n) { return n*n; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > bool inside(T a, T b, T c) { return a<=b && b<=c; }
template< class T > void setmax(T &a, T b) { if(a < b) a = b; }
template< class T > void setmin(T &a, T b) { if(b < a) a = b; }
template< class T > T power(T N,T P){  return (P==0)?  1: N*power(N,P-1); }

LLU a[10100] ;
LLU b[10100] ;
LLU c ;
int n ;

LLU solve(LLU x)
{
         LLU ret = 0 ;
         int i ;

         rep(i,0,n)
         {
                  ret += (a[i]*x)/b[i] ;
                  if(ret>c)                 return c+(LLU)1 ;
         }

         return ret ;
}

LLU low(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val>=c)        return low(b,m) ;
         return low(m+1,e) ;
}

LLU high(LLU b, LLU e)
{
         if(b==e)                   return b ;

         LLU m = (LLU)1+(b+e)/(LLU)2 ;

         LLU val = solve(m) ;

         if(val<=c)        return high(m,e) ;
         return high(b,m-1) ;
}

int main()
{
         int T,t=1,m,i,j,k;
         //freopen("in.txt","r",stdin);
         //freopen("out.txt","w",stdout);
         //scanf("%d",&T);
         //for(t=1;t<=T;t++)
         //while(scanf("%d",&n)==1)
         scanf("%d",&n) ;
         //scanf("%d",&n) ;

         cin>>c ;

         if(c<(LLU)n)
         {
                  //while(1) ;
                  puts("0") ;
                  return 0 ;
         }

         c -= (LLU)n ;

         bool f = 1 ;

         rep(i,0,n)
         {
                  scanf("%d",&m);
                  a[i] = m ;
                  scanf("%d",&m);
                  b[i] = m ;

                  if(a[i])          f = 0 ;
         }

         if(f)
         {
                  while(1) ;
                  if(c==0)
                  {
                           puts("-1") ;
                           return 0 ;
                  }
                  {
                           puts("0") ;
                           return 0 ;
                  }
         }

         //if(c==0)          while(1) ;

         LLU Inf = 1000000000 ;
         Inf *= Inf ;
         Inf *= (LLU)2 ;

         LLU l = low(1,Inf) ;
         LLU h = low(1,Inf) ;

         if(solve(l)!=c || solve(h)!=c || l>h)
         {
                  puts("0") ;
                  return 0 ;
         }

         LLU ans = h-l+(LLU)1 ;

         cout<<ans<<endl ;
         //cout<<h<<endl ;
        // cout<<l<<endl ;

         //printf("Case %d: ",t);

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#define ll long
#define maxn 10003
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FO(i,a,b) for(ll i=a;i<b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define FOD(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
using namespace std;
int a[maxn],b[maxn];
int n,c,ans=-1;
main() {
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	cin >> n >> c;
	FOR (i,1,n) cin >> a[i] >> b[i];
	int dau=1,cuoi=c+1,x;
	do {
		x=(dau+cuoi)/2;
		int d=0;
		FOR (i,1,n) d+=1+a[i]*x/b[i];
		if (d==c) {
			cuoi=x;
		} else dau=x+1;
	}	while (dau<cuoi);
	int ans1 = dau;

	if (ans1>c) {
		cout << 0;
		return 0;
	}

	dau =ans1,cuoi=c+1;
	do {
		x=(dau+cuoi)/2;
		int d=0;
		FOR (i,1,n) d+=1+a[i]*x/b[i];
		if (d>c) cuoi=x; else dau=x+1;
	}	while (dau<cuoi);
	int ans2 = dau;

	cout << ans2 -ans1;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#define ll long
#define maxn 10003
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FO(i,a,b) for(ll i=a;i<b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define FOD(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
using namespace std;
int a[maxn],b[maxn];
int n,c,ans=-1;
main() {
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	cin >> n >> c;
	FOR (i,1,n) cin >> a[i] >> b[i];
	int dau=1,cuoi=c+1,x;
	do {
		x=(dau+cuoi)/2;
		int d=0;
		FOR (i,1,n) d+=1+a[i]*x/b[i];
		if (d==c) {
			cuoi=x;
		} else dau=x+1;
	}	while (dau<cuoi);
	int ans1 = dau;

	if (ans1>c) {
		cout << -1;
		return 0;
	}

	dau =ans1,cuoi=c+1;
	do {
		x=(dau+cuoi)/2;
		int d=0;
		FOR (i,1,n) d+=1+a[i]*x/b[i];
		if (d>c) cuoi=x; else dau=x+1;
	}	while (dau<cuoi);
	int ans2 = dau;

	cout << ans2 -ans1;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#define ll long
#define maxn 10003
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FO(i,a,b) for(ll i=a;i<b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define FOD(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define mp make_pair
using namespace std;
int a[maxn],b[maxn];
int n,c,ans;
main() {
	//freopen("test.in","r",stdin);
	//freopen("test.out","w",stdout);
	cin >> n >> c;
	FOR (i,1,n) cin >> a[i] >> b[i];
	int x=0,d;
	while (1) {
		x++;
		d=0;
		FOR (i,1,n) d+=1+a[i]*x/b[i];
		if (d==c) ans++;
		if (d>c) break;
	}
	cout << ans;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		if(a[i]*x>=b[i]) ret+=(a[i]*x/b[i]+1);
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,retl=-1,retr=-1;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retl=mid;
		if(check(mid)>=c) r=mid-1;
		else l=mid+1;
	}
	l=0,r=inf;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retr=mid;
		if(check(mid)>c) r=mid-1;
		else l=mid+1;
	}
	if(retl+1) cout<<retr-retl+1<<endl;
	else cout<<0<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		if(a[i]>inf/(x+1)) return inf;
		else ret+=(a[i]*x/b[i]+1);
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,retl=-1,retr=-1;
	if(n>c)
	{
		cout<<0<<endl;
		return 0;
	}
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)>=c) r=mid-1,retl=mid;
		else l=mid+1;
	}
	if(retl==0) retl++;
	l=0,r=inf;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)>c) r=mid-1;
		else l=mid+1,retr=mid;
	}
	cout<<retr-retl+1<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		ret+=(a[i]*x/b[i])+1;
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,retl=-1,retr=-1;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retl=mid;
		if(check(mid)>=c) r=mid-1;
		else l=mid+1;
	}
	l=0,r=inf;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retr=mid;
		if(check(mid)>c) r=mid-1;
		else l=mid+1;
	}
	cout<<retr-retl+1<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		if(a[i]>inf/(x+1)) return inf;
		else ret+=(a[i]*x/b[i]+1);
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,retl=-1,retr=-1;
	if(n>c)
	{
		cout<<0<<endl;
		return 0;
	}
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)>=c) r=mid-1,retl=mid;
		else l=mid+1;
	}
	l=0,r=inf;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)>c) r=mid-1;
		else l=mid+1,retr=mid;
	}
	cout<<retr-retl+1<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		ret+=(a[i]*x/b[i])+1;
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,retl=-1,retr=-1;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retl=mid;
		if(check(mid)>=c) r=mid-1;
		else l=mid+1;
	}
	l=0,r=inf;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retr=mid;
		if(check(mid)>c) r=mid-1;
		else l=mid+1;
	}
	if(retl+1) cout<<retr-retl+1<<endl;
	else cout<<0<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		ret+=(a[i]*x/b[i]);
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,retl=-1,retr=-1;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retl=mid;
		if(check(mid)>=c) r=mid-1;
		else l=mid+1;
	}
	l=0,r=inf;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retr=mid;
		if(check(mid)>c) r=mid-1;
		else l=mid+1;
	}
	if(retl+1) cout<<retr-retl+1<<endl;
	else cout<<0<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		if(a[i]>inf/(x+1)) return inf;
		else ret+=(a[i]*x/b[i]+1);
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,retl=-1,retr=-1;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retl=mid;
		if(check(mid)>=c) r=mid-1;
		else l=mid+1;
	}
	l=0,r=inf;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retr=mid;
		if(check(mid)>c) r=mid-1;
		else l=mid+1;
	}
	if(retl+1) cout<<retr-retl+1<<endl;
	else cout<<0<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		if(a[i]>inf/(x+1)) return inf;
		else ret+=(a[i]*x/b[i]+1);
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,retl=-1,retr=-1;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)>=c) r=mid-1,retl=mid;
		else l=mid+1;
	}
	l=0,r=inf;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)>c) r=mid-1;
		else l=mid+1,retr=mid;
	}
	cout<<retr-retl+1<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		if(a[i]>inf/(x+1)) return inf;
		else ret+=(a[i]*x/b[i]+1);
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,retl=-1,retr=-1;
	if(n>c)
	{
		cout<<0<<endl;
		return ;
	}
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)>=c) r=mid-1,retl=mid;
		else l=mid+1;
	}
	l=0,r=inf;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)>c) r=mid-1;
		else l=mid+1,retr=mid;
	}
	cout<<retr-retl+1<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		ret+=(a[i]*x/b[i])+1;
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,ret=-1;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)>=c) r=mid-1,ret=mid;
		else l=mid+1;
	}
	cout<<ret<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string.h>

const int N=10010;
const long long inf=1e18;

using namespace std;

int n;
long long a[N],b[N],c;

long long check(long long x)
{
	long long ret=0;
	for(int i=0;i<n;i++)
		if(a[i]*x>b[i]) ret+=(a[i]*x/b[i]+1);
	return ret;
}

int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>a[i]>>b[i];
	long long l=0,r=inf,retl=-1,retr=-1;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retl=mid;
		if(check(mid)>=c) r=mid-1;
		else l=mid+1;
	}
	l=0,r=inf;
	while(l<=r)
	{
		long long mid=(l+r)>>1;
		if(check(mid)==c) retr=mid;
		if(check(mid)>c) r=mid-1;
		else l=mid+1;
	}
	if(retl+1) cout<<retr-retl+1<<endl;
	else cout<<0<<endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <climits>

using namespace std;

#define LL unsigned long long
#define TOP 100100

int n;
LL c;
LL a[10000];
LL b[10000];

LL calc(LL mid)
{
	if (mid == 0) return 0;
	LL res = 0;
	for (int i = 0; i < n; ++i)
		res += 1+a[i]*mid/b[i];
	return res;
}

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

	LL low = 1, hig = TOP, bot = TOP, top = 0;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid), top = max(top, mid);
		if (res >= c) hig = mid;
		else low = mid+1;
	}
	low = 1, hig = TOP;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig+1)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid), top = max(top, mid);
		if (res <= c) low = mid;
		else hig = mid-1;
	}
	if (calc(1) == c) bot = 1;
	if (calc(TOP) == c) top = TOP;
	if (bot <= top && bot > 0 && top <= TOP) cout << top-bot+1 << endl;
	else cout << 0 << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <climits>

using namespace std;

#define LL unsigned long long
#define TOP LLONG_MAX

int n;
LL c;
LL a[10000];
LL b[10000];
bool g;

LL solve(LL a, LL x, LL b)
{
	g = 1;
	if (a == 0) return 0;
	if (x > c*b/a)
	{
		g = 0;
		return 0;
	}
	long double aux = a;
	aux /= b;
	aux *= x;
	return aux;
}

LL calc(LL mid)
{
	if (mid == 0) return 0;
	LL res = 0;
	g = 1;
	for (int i = 0; i < n; ++i)
	{
		res += 1;
		LL tmp = solve(a[i],mid,b[i]);
		if (!g) return 0;
		else res += tmp;
	}
	return res;
}

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

	LL low = 1, hig = TOP, bot = TOP, top = 0;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid), top = max(top, mid);
		if (res >= c || !g) hig = mid;
		else low = mid+1;
	}
	low = 1, hig = TOP;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig+1)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid), top = max(top, mid);
		if (res <= c && g) low = mid;
		else hig = mid-1;
	}
	LL mid = 1;
	if (calc(mid) == c) bot = min(bot, mid), top = max(top, mid);
	mid = TOP;
	if (calc(mid) == c) bot = min(bot, mid), top = max(top, mid);
	if (bot <= top && bot > 0 && top <= TOP) cout << top-bot+1 << endl;
	else cout << 0 << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <climits>

using namespace std;

#define LL unsigned long long

int n;
LL c;
LL a[10000];
LL b[10000];

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

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

	LL low = 1, hig = INT_MAX, bot = INT_MAX, top = 0;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid);
		if (res >= c) hig = mid;
		else low = mid+1;
	}
	low = 1, hig = INT_MAX;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig+1)/2;
		LL res = calc(mid);
		if (res == c) top = max(top, mid);
		if (res <= c) low = mid;
		else hig = mid-1;
	}
	if (bot <= top) cout << top-bot+1 << endl;
	else cout << 0 << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <climits>

using namespace std;

#define LL unsigned long long

int n;
LL c;
LL a[10000];
LL b[10000];

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

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

	LL bot = INT_MAX, top = 0;

	for (LL i = 1; i <= 10000; ++i)
	{
		if (calc(i) == c) bot = min(bot, i), top = max(top, i);
	}

	if (bot <= top) cout << top-bot+1 << endl;
	else cout << 0 << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <climits>

using namespace std;

#define LL unsigned long long

int n;
LL c;
LL a[10000];
LL b[10000];

LL calc(LL mid)
{
	if (mid == 0) return 0;
	LL res = 0;
	for (int i = 0; i < n; ++i)
		res += 1+a[i]*mid/b[i];
	return res;
}

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

	LL low = 1, hig = 10100, bot = INT_MAX, top = 0;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid);
		if (res >= c) hig = mid;
		else low = mid+1;
	}
	low = 1, hig = 10100;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig+1)/2;
		LL res = calc(mid);
		if (res == c) top = max(top, mid);
		if (res <= c) low = mid;
		else hig = mid-1;
	}
	if (bot <= top && bot > 0 && top <= 10000) cout << top-bot+1 << endl;
	else cout << 0 << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <climits>

using namespace std;

#define LL unsigned long long
#define TOP LLONG_MAX

int n;
LL c;
LL a[10000];
LL b[10000];
bool g;

LL solve(LL a, LL x, LL b)
{
	g = 1;
	if (a == 0) return 0;
	if (x > c*b/a)
	{
		g = 0;
		return 0;
	}
	if (c*b < (long double)x*a)
	{
		g = 0;
		return 0;
	}
	return x*a/b;
}

LL calc(LL mid)
{
	if (mid == 0) return 0;
	LL res = 0;
	g = 1;
	for (int i = 0; i < n; ++i)
	{
		res += 1;
		LL tmp = solve(a[i],mid,b[i]);
		if (!g) return 0;
		else res += tmp;
	}
	return res;
}

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

	LL low = 1, hig = TOP, bot = TOP, top = 0;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid), top = max(top, mid);
		if (res >= c || !g) hig = mid;
		else low = mid+1;
	}
	low = 1, hig = TOP;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig+1)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid), top = max(top, mid);
		if (res <= c && g) low = mid;
		else hig = mid-1;
	}
	LL mid = 1;
	if (calc(mid) == c) bot = min(bot, mid), top = max(top, mid);
	mid = TOP;
	if (calc(mid) == c) bot = min(bot, mid), top = max(top, mid);
	if (bot <= top && bot > 0 && top <= TOP) cout << top-bot+1 << endl;
	else cout << 0 << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <climits>
#include <cassert>

using namespace std;

#define LL unsigned long long
#define TOP LLONG_MAX

int n;
LL c;
LL a[10000];
LL b[10000];
bool g;

LL solve(LL a, LL x, LL b)
{
	g = 1;
	if (a == 0) return 0;
	if (x > c*b/a)
	{
		g = 0;
		return 0;
	}
	if (c*b < (long double)x*a)
	{
		g = 0;
		return 0;
	}
	return x*a/b;
}

LL calc(LL mid)
{
	if (mid == 0) return 0;
	LL res = 0;
	g = 1;
	for (int i = 0; i < n; ++i)
	{
		res += 1;
		LL tmp = solve(a[i],mid,b[i]);
		if (!g) return 0;
		else res += tmp;
	}
	return res;
}

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

	LL low = 1, hig = TOP, bot = TOP, top = 0;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid), top = max(top, mid);
		if (res >= c || !g) hig = mid;
		else low = mid+1;
	}
	low = 1, hig = TOP;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig+1)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid), top = max(top, mid);
		if (res <= c && g) low = mid;
		else hig = mid-1;
	}
	if (top == TOP && n == c) cout << -1 << endl;
	else if (bot <= top && bot > 0 && top < TOP) cout << top-bot+1 << endl;
	else cout << 0 << endl;

	return 0;
}


#include <cstdio>
#include <iostream>
#include <climits>

using namespace std;

#define LL unsigned long long

int n;
LL c;
LL a[10000];
LL b[10000];

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

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

	LL low = 1, hig = 10100, bot = INT_MAX, top = 0;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig)/2;
		LL res = calc(mid);
		if (res == c) bot = min(bot, mid);
		if (res >= c) hig = mid;
		else low = mid+1;
	}
	low = 1, hig = 10100;
	while (low != hig && low > 0)
	{
		LL mid = (low+hig+1)/2;
		LL res = calc(mid);
		if (res == c) top = max(top, mid);
		if (res <= c) low = mid;
		else hig = mid-1;
	}
	if (bot <= top && bot > 0 && top <= 10000) cout << top-bot+1 << endl;
	else cout << 0 << endl;

	return 0;
}


#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;
	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 << 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;
	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;
}