/** Problem: wrong
  * Solution by: Semyon Dyatlov
  **/
#include <stdio.h>

int gcd(int a, int b)
{
  while (b)
  {
    int r = a%b;
    a = b;
    b = r;
  }
  return a;
}

int main()
{
  freopen("wrong.in","rt",stdin);
  freopen("wrong.out","wt",stdout);

  int n, k;
  scanf("%d%d",&n,&k);
  printf("%d\n",n-n/gcd(n,k));

  return 0;
}