#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<ll, ll>;
const ll MOD = 1000000007;
ll gcd(ll a, ll b)
{
	if (b == 0) return a;
	else return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll a, ll b) {
	ll ans = 1;
	if (b <= 0)return 1;
	else if (b % 2 == 0)return(pow(a * a, b / 2));
	else return (a * pow(a, b - 1));
}
ll modpow(ll x, ll n, ll mod) {
	x %= mod;
	if (n == 0)
		return 1;
	if (x == 1)return 1;
	if (n % 2 == 0)
		return (modpow((x * x) % mod, n / 2, mod) % mod);
	else
		return (x * modpow(x, n - 1, mod)) % mod;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
void solveA() {
	int x, y, z; cin >> x >> y >> z;
	int num = 0;
	for (int i = 1000000; i >= 0; i--)if (y * z > x* i) {
		num = i; break;
	}
	cout << num << endl;

}
void solveB() {
	int n, m; cin >> n >> m;
	vector<int>a(1005, 0);
	vector<int>b(1005, 0);
	vector<int>ab(1005, 0);
	rip(i, n) {
		int d; cin >> d;
		a[d]++, ab[d]++;
	}
	rip(i, m) {
		int e; cin >> e;
		b[e]++, ab[e]++;
	}
	for (int i = 1; i <= 1000; i++) {
		if (ab[i] != 0 && (ab[i] == a[i] || ab[i] == b[i]))cout << i << endl;
	}
}
void solveC() {
	int a, b; cin >> a >> b;
	if (2 * a <= b)cout << b / 2 << endl;
	else {
		int c = b - a;
		for (int i = c; i >= 1; i--) {
			if (a % i == 0 || b % i == 0) {
				cout << i << endl;
				break;
			}
			else if (a/i + 1 <b/i - 1) {
				cout << i << endl;
				break;
			}
		}
	}
}
void solveD() {
	int N,P; cin >> N>>P;
	ll ans = modpow(P - 2, N-1, MOD)*(P-1);
	cout << ans % MOD << endl;
}
void solveE() {
}
void solveF() {
}
int main() {
	solveD();
}

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) 
#define X first
#define Y second 
#define nl '\n'
#define AC return 0
#define pb(a) push_back(a) 
#define mst(a,b) memset(a, b, sizeof a)
#define rep(i,n) for(int i = 0; (i)<(n); i++)
#define rep1(i,n) for(int i = 1; (i)<=(n); i++)
#define scd(a) scanf("%lld", &a)
#define scdd(a,b) scanf("%lld%lld", &a, &b)
#define scs(s) scanf("%s", s)
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll INF = (ll)0x3f3f3f3f3f3f3f, MAX = 9e18, MIN = -9e18;
const int N = 1e6+10, M = 2e6+10, mod = 1e9+7, inf = 0x3f3f3f;
ll a[N]; 


int main()
{
	IOS;
	string s, t;
	cin>>s>>t;
	if(s[0] == 'Y') 
		rep(i, t.size())
			cout<<char(t[i] >= 'a'&&t[i] <= 'z' ? t[i]-32 : t[i]);
	else
		rep(i, t.size())
			cout<<t[i];
	AC;
} 