#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char c = getchar();
  long long x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
const long long M = 5e5;
long long cnt, a[M], b[M], n;
void solve(long long l, long long r) {
  if (l == r) return;
  long long Mid = (l + r) >> 1;
  solve(l, Mid), solve(Mid + 1, r);
  long long ll = l, rr = r;
  while (ll <= rr) {
    a[++cnt] = ll, b[cnt] = rr;
    ll++, rr--;
  }
}
signed main() {
  n = read();
  long long k = 1;
  while (k * 2 < n) k *= 2;
  solve(1, k), solve(n - k + 1, n);
  cout << cnt << endl;
  for (long long i = 1; i <= cnt; i++) cout << a[i] << ' ' << b[i] << endl;
  return 0;
}
