#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = 0;
  int x = 0, flag = 1;
  while (!isdigit(ch)) {
    ch = getchar();
    if (ch == '-') flag = -1;
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  }
  return x * flag;
}
const int mo = 998244353;
int tot;
struct node {
  int x, y;
} p[550000];
void solve(int l, int r) {
  if (l == r) return;
  solve(l, ((l + r) >> 1));
  solve(((l + r) >> 1) + 1, r);
  for (int i = l, j = ((l + r) >> 1) + 1; i <= ((l + r) >> 1) && j <= r;
       i++, j++)
    p[++tot] = {i, j};
}
int F(int x, int y) {
  return ((x ^ y ^ (x + y)) + (x + y) + (x / y) + (y / x)) % mo;
}
int a[550000], f[550000], g[550000], nw[550000];
int main() {
  int n = read(), m = n, cnt = 0;
  while (m) a[++cnt] = ((+m) & (-m)), m -= ((+m) & (-m));
  for (int i = 1, k = 1; i <= cnt; i++) solve(k, k + a[i] - 1), k += a[i];
  if (cnt <= 2) {
    printf("%d\n", tot);
    for (int i = 1; i <= tot; i++) printf("%d %d\n", p[i].x, p[i].y);
    return 0;
  }
  for (int i = 1; i <= a[1]; i++) nw[i] = i;
  for (int i = 1; i <= n - a[1] - a[cnt]; i++) f[i] = a[1] + i;
  for (int i = 1; i <= a[cnt]; i++) g[i] = n - a[cnt] + i;
  for (int i = 1, t = 0, k = 0, len = a[1]; i <= cnt - 2; i++) {
    while (len < a[i + 1]) {
      int tmp = len;
      for (int j = 1; j <= tmp; j++)
        p[++tot] = {nw[j], g[++t]}, nw[++len] = g[t];
    }
    int tmp = len;
    for (int j = 1; j <= tmp; j++) p[++tot] = {nw[j], f[++k]}, nw[++len] = f[k];
  }
  printf("%d\n", tot);
  for (int i = 1; i <= tot; i++) printf("%d %d\n", p[i].x, p[i].y);
  return 0;
}
