/*
#include <stdio.h>
int n, a, b, d[1010];
long long int subsetsum(int a, int b)
{
long long int c=0;
int e;
for(e=a; e<=b; e++)
{
c = c + d[e];
}
return c;
}
int main()
{
scanf("%d", &n);
for(int i=1; i<=n; i++)
scanf("%d", &d[i]);
scanf("%d%d", &a, &b);
printf("%lld\n", subsetsum(a, b));
}
*/
/*
#include <stdio.h>
int n, k, d[1010];
int upper_bound(int k)
{
int e,f=1;
for(e=1; e<=n; e++)
{
if(d[e]>k)
{
return e;
}
}
return n+1;
}
int main()
{
scanf("%d", &n);
for(int i=1; i<=n; i++)
scanf("%d", &d[i]);
scanf("%d", &k);
printf("%d\n", upper_bound(k));
}
*/
/*
#include <stdio.h>
int n, d[110];
int f()
{
int e,h=0;
for(e=0; e<n; e++)
{
if(d[e]>d[h])
{
h = e;
}
}
return h+1;
}
int main()
{
scanf("%d", &n);
for(int i=0; i<n; i++)
scanf("%d", &d[i]);
printf("%d", f());
return 0;
}
*/
/*
//n n/10 n%10 a
//1325 132 5 5
//132 13 2 5*10+2 52
//13 1 3 52*10+3 523
//1 0 1 5231
//0
#include <stdio.h>
long long int n;
long long int f(long long int n)
{
long long int a,b,c,d;
if(n==1)
{
return 1;
}
b = n/10;
c = n%10;
for(a=n; a>=1; a--)
{
c = c * 10 + b%10;
b = b / 10;
if(b==0)
{
break;
}
}
return c;
}
int main()
{
scanf("%lld", &n);
printf("%lld\n", f(n));
}
*/
#include <stdio.h>
int a, b;
int gcd(int a, int b)
{
int c,d=0;
for(c=1; c<=100; c++)
{
if(a%2==0&&b%2==0)
{
d = d + a/2;
}
else if(a%3==0&&b%3==0)
{
d = d + a/3;
}
else if(a%5==0&&b%5==0)
{
d = d + a/5;
}
else if(a%7==0&&b%7==0)
{
d = d + a/7;
}
else
{
break;
}
}
return d;
}
int main()
{
scanf("%d%d", &a, &b);
printf("%d\n", gcd(a, b));
}