#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll powermd(long long x,  int y,	ll p)
{
    ll res = 1;     // Initialize result
 
    x = x % p; // Update x if it is more than or
                // equal to p
  
    // if (x == 0) return 0; // In case x is divisible by p;
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
//ll mpow(ll x,ll y){
//	if(y==0)
//		return 1;
//	ll res=mpow(x,y/2);
//	res=res*res%mod;
//	if(y&1)
//		res=res*x%MOD;
//	return res;
//}
// ll mpow(ll n,ll t){
// 	if(t==0) return 1;
// 	ll ret=mpow(n,t/2);
// 	ret=ret*ret%MOD;
// 	if(t%2==1) ret=ret*n%MOD;
// 	return ret;
// }
void solve(){
	ll n,p;
	cin>>n>>p;
	cout<<(powermd(p-2,n-1,1000000007)*(p-1))%1000000007;
}
int main(){
// 	ios::sync_with_stdio(false);
// 	cout.tie(0);
// 	cin.tie(NULL);
	int t;
	// cin>>t;
	t=1;
    while(t--) {
    	// int n;
    	// cin>>n;
    	solve();
	}
}
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */


#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class AAtCoderJumper {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      for(int i=0; i<n; i++) {
        int a = i*2;
        int b = i*2+1;
        cout << a%n+1 << ' ' << b%n+1 << endl;
      }
    }
};

signed main() {
  AAtCoderJumper solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}