N,p = map(int,input().split()) fibo = [0] * (N + 5) fibo[1] = 1 P = 10 ** 9 + 7 for i in range(2,N): fibo[i] = (p * fibo[i-1] + fibo[i-2]) % P ans = 0 S = 0 for i in range(N): S += fibo[i] ans += S * fibo[i] ans %= P print(ans)