#include <bits/stdc++.h>
using namespace std;
const int maxn = 555555, mod = 998244353;
inline long long read() {
  char ch = getchar();
  long long x = 0, f = 0;
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
inline int qmo(int x) { return x + (x >> 31 ? mod : 0); }
int n, lim = 1, ans[maxn][2], al;
void work(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1;
  work(l, mid);
  work(mid + 1, r);
  for (int i = (l); i <= (mid); i++)
    ans[++al][0] = i, ans[al][1] = mid + i - l + 1;
}
int main() {
  n = read();
  while (lim <= n) lim <<= 1;
  lim >>= 1;
  work(1, lim);
  work(n - lim + 1, n);
  printf("%d\n", al);
  for (int i = (1); i <= (al); i++) printf("%d %d\n", ans[i][0], ans[i][1]);
}
