import java.util.Arrays; import java.util.Scanner; public class N016 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long x=sc.nextLong(),n=sc.nextLong(); long[] a=new long[(int)n]; for(long i=0;i=20){ while(dif>=20){ dif-=20; mem=(mem*buf)%beki; } mem=(mem*((int)Math.pow(2, dif)%beki))%beki; }else{ mem*=((int)Math.pow(x, dif)%beki); } ans=(ans+mem)%beki; cnt+=(a[i]-cnt); } System.out.println(ans); } }