#include <bits/stdc++.h>
#include <list>
using namespace std;
#define rep(i,t,n) for(int64_t i=t;i<n;i++)
#define Sort(a) sort(a.begin(),a.end())
#define rSort(a,n,m) sort(a.begin()+n-1,a.begin()+m)
#define Reverse(a) reverse(a.begin(),a.end())
#define rReverse(a,n,m) reverse(a.begin()+n-1,a.begin()+m)
#define MOD 1000000007
#define sign(i) -1*pow(-1,i)
#define vi(A,N,i)  vector<int64_t> A(N,i)
#define vs(A,N,i)  vector<string> A(N,i)
#define vb(A,N,i)  vector<bool> A(N,i)
#define INF ((1LL<<62)-(1LL<<31))
//((a+b+c)-max(a,max(b,c))-min(a,min(b,c)))

/*template <class T>

}*/


//cout << fixed << setprecision(桁数);

int64_t def_str(string x,string y){
  int64_t def=0;
  rep(i,0,(int64_t)x.size()){
    if(x[i]!=y[i]){
      def++;
    }
  }
  return def;
}



////
class ModularExponentiation
{
    int64_t ans;                    // Answer
public:
    int64_t compME(int64_t, int64_t, int64_t);  // Compute Modular Exponentiation
};

/*
 * Compute Modular Exponentiation
 */
int64_t ModularExponentiation::compME(int64_t u, int64_t e, int64_t m)
{
    if (e == 0) return 1;

    ans = compME(u, e / 2, m);
    ans = (ans * ans) % m;
    if (e % 2 == 1) ans = (ans * u) % m;

    return ans;
}
////
int main() {
  int64_t a,b,c,d,f,now_ans=0,mlt_ans=1;
  //double a,b,c,d,e,f,ans=0,now_ans=0,mlt_ans=1;
  string x,y,z;
  char s,t,u;
  bool frag=false,frag1=false,frag2=false;
  vector<int64_t> A{},B{},C{},D{};
  vector<string> Cg{},Dg{};
  vector<char> E{},F{};
  vector<bool> G(26,false);
  cin>>a>>b;
  //cin>>x;
  //cin>>s>>t;////////////////////////
  ModularExponentiation objMain;
  c = objMain.compME(b-2, a-1, MOD);
  cout<<(c*(b-1))%MOD;
}
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#ifdef _OLIMPOLOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1337
#endif
void debug_out() { cout << "\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
template<typename T1> 
void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = V.size() - 1;
    for (int i = start; i <= end; i++) {
        cout << V[i] + add << ((i == end) ? "\n" : " ");
    }
}
template<typename T1> 
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1> 
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }

#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
template<typename T1> 
T1 gcd(const T1 &a, const T1 &b) {
    if (a == 0 || b == 0) return a + b;
    return gcd(b, a %b);
}
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------
#define MAX 500001
#define MOD 1000000007

bool isP(int x) {
    for(int i = 2; i *i <= x; i++)
        if (x % i == 0) 
            return 0;
    return 1;
}
vector<int> P;
vector<ll> S;
void comb(int i, ll v) {
    if (i == P.size()) {
        if (v > 1)
            S.push_back(v);
        return;
    }
    comb(i+1, v);    
    comb(i+1, v * P[i]);
}

void solve() {

    reps(p, 2, 50) 
        if (isP(p))
            P.push_back(p);
    comb(0, 1);
    debug(S.size());
    sort(all(S));
    int n; cin >> n;
    vector<int> N(n);
    rep(i,n) cin >> N[i];
    for(const ll s : S) {
        bool f = 1;
        for(int i = 0; f && i < n; i++) {
            f = (gcd((ll)N[i], s) != 1);
        }
        if (f) out(s);
    }
}
 
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int test = 1;
    // #ifdef _OLIMPOLOCAL
         //cin >> test;
    // #endif
    rep(testCase, test) {
        #ifdef _OLIMPOLOCAL
            cout << "------------------ TESTCASE: " << testCase << " -------------\n";
        #endif
        solve();
    }
    return 0;
}