using System;
public class Zadacha3
{
public static void Main()
int N = Convert.ToInt32(Console.ReadLine());
int k = Convert.ToInt32(Console.ReadLine());
int sum = 0;
for (int currentDegree = 1; currentDegree <= N; currentDegree++)
sum += Convert.ToInt32(Math.Pow(k, currentDegree));
}
Console.WriteLine(sum);