#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, M = 2e3 + 10;
int n, c, mx, mn, kd;
bool ok;
vector<int> now[15];
pair<int, int> ans[N];
void solve(int l, int r) {
  if (l == r) return;
  int mid = (l + r) / 2;
  solve(l, mid);
  solve(mid + 1, r);
  for (int i = l, j = mid + 1; i <= mid; i++, j++) {
    ans[++c] = pair<int, int>(i, j);
  }
}
int main() {
  scanf("%d", &n);
  mn = 15;
  for (int i = 14; i >= 0; --i) {
    if (n >> i & 1) {
      kd++;
      solve(n - (1 << i) + 1, n);
      for (int j = n - (1 << i) + 1; j <= n; ++j) {
        now[i].push_back(j);
      }
      mx = max(mx, i);
      mn = min(mn, i);
      n -= (1 << i);
    }
  }
  while (kd > 2) {
    for (int i = 0; i < (1 << mn); ++i) {
      int v = now[mx].back();
      now[mx].pop_back();
      now[mn].push_back(v);
      ans[++c] = pair<int, int>(v, now[mn][i]);
    }
    while (kd > 2 && !now[mn + 1].empty()) {
      for (int i = 0; i < (1 << (mn + 1)); i++) {
        ans[++c] = pair<int, int>(now[mn + 1][i], now[mn][i]);
        now[mn + 1].push_back(now[mn][i]);
      }
      mn++;
      kd--;
    }
    if (now[mn + 1].empty()) {
      for (int i = 0; i < (1 << (mn + 1)); i++) {
        now[mn + 1].push_back(now[mn][i]);
      }
      mn++;
    }
  }
  printf("%d\n", c);
  for (int i = 1; i <= c; ++i) {
    pair<int, int> x = ans[i];
    printf("%d %d\n", x.first, x.second);
  }
  return 0;
}
