# coding : utf-8 P, K = gets.split(' ').map{|s|s.to_i} a = Array.new(K+1) b = Array.new(K+1) a[0] = 1 b[0] = 0 K.times do |i| a[i+1] = (P+1) * a[i] + 2 * b[i] b[i+1] = (P-1) * a[i] + 2 * (P-1) * b[i] end p a[K] % 1_000_000_007