#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <list>
using namespace std;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
if (n%m==0)
printf("0\n");
else
{
if (m%n==0)
printf("%d\n",(m/n-1)*n);
else
{
int ans=0;
int total=0;
int counter=1;
int left=0;
while (counter<=n)
{
total=m+left;
if (total%n!=0)
{
ans+=total/n;
left=total-total/n*n;
}
else
{
ans+=total/n-1;
left=0;
}
counter++;
}
printf("%d\n",ans);
}
}
}