#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e16;
const long long MN = 3e5 + 10;
const long long mod = 998244353;
const long double EPS = 1e-8;
int N, M;
pair<long long, long long> A[MN];
pair<long long, long long> ans[MN];
int Q = 0;
void solve(int x, int k) {
  if (k == 2) {
    ans[Q++] = pair<long long, long long>(x, x + 1);
    return;
  }
  solve(x, k / 2);
  solve(x + k / 2, k / 2);
  for (int i = x; i < x + k / 2; i++)
    ans[Q++] = pair<long long, long long>(i, i + k / 2);
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> N;
  if (N <= 2) {
    cout << "0\n";
    return 0;
  }
  int K = 1;
  while (K <= N) K *= 2;
  K /= 2;
  solve(1, K);
  solve(N - K + 1, K);
  cout << Q << "\n";
  for (int i = 0; i < Q; i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
  return 0;
}
