#include <bits/stdc++.h>
using namespace std;
int n, qwq = 1, ans;
struct cccp {
  int c, d;
} a[500010];
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ '0');
    c = getchar();
  }
  return x * f;
}
void solve(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  solve(l, mid);
  solve(mid + 1, r);
  for (int i = l; i <= mid; ++i) {
    a[++ans].c = i;
    a[ans].d = i - l + 1 + mid;
  }
}
int main() {
  n = read();
  if (n == 1) {
    puts("0");
    return 0;
  }
  while (1) {
    if (qwq * 2 <= n) {
      qwq *= 2;
    } else {
      break;
    }
  }
  solve(1, qwq);
  solve(n - qwq + 1, n);
  printf("%d\n", ans);
  for (int i = 1; i <= ans; ++i) {
    printf("%d %d\n", a[i].c, a[i].d);
  }
  return 0;
}
