#include <bits/stdc++.h>
using namespace std;
const int maxn = 150000, maxm = 500000;
int n, N, m, A[maxm + 5], B[maxm + 5], ti, vis[maxn + 5];
int main() {
  scanf("%d", &n);
  N = 1;
  while (N < n) N <<= 1;
  N >>= 1;
  for (int j = 1; j < N; j <<= 1)
    for (int i = 1; i < N; i += j << 1)
      for (int k = 0; k < j; k++) m++, A[m] = i + k, B[m] = i + k + j;
  for (int j = 1; j < N; j <<= 1)
    for (int i = 1; i < N; i += j << 1)
      for (int k = 0; k < j; k++)
        m++, A[m] = n - N + i + k, B[m] = n - N + i + k + j;
  printf("%d\n", m);
  for (int i = 1; i <= m; i++) printf("%d %d\n", A[i], B[i]);
  return 0;
}
