#include<bits/stdc++.h>
//#include
#define ll long long
using namespace std;
ll gcd(ll a,ll b)
{
if(!a)
{return b;}
else{
gcd(b%a,a);
}
}
ll resolve(ll num,char a[])
{
ll mod=0;
for(ll i=0;i<strlen(a);i++)
{
mod=(mod*10+a[i]-‘0’)%num;
}
return mod;
}
#define ll long long
int main()
{
ll n;
char a[255];
cin>>n;
cin>>a;
ll x;
x=resolve(n,a);
ll y=gcd(n,x);
cout<<y<<endl;
return 0;
}