#include <cstdio>
#define Inline __attri\
bute__( ( optimize ("-O2") ) )
Inline int Main ()
{
freopen ("jos.in", "r", stdin);
freopen ("jos.out", "w", stdout);
int N, M;
scanf ("%d %d", &N, &M);
register int s = 0, i, L = N - 16;
for (i = 2; i <= L; )
{
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
for (s += M; s >= i; s -= i); ++ i;
}
for (; i <= N; ++ i)
for (s += M; s >= i; s -= i);
printf ("%d",s + 1);
}
int ZlycerQan = Main ();
int main (int argc, char *argv[]) { return 0; }