#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, top;
pair<int, int> ans[N];
void work(int l, int r) {
  for (int d = 1; d < r - l + 1; d <<= 1)
    for (int i = 0; i < r - l; i++)
      if (!(i & d)) ans[++top] = pair<int, int>(l + i, l + i + d);
}
int main() {
  scanf("%d", &n);
  int l = 1;
  for (; l * 2 <= n; l *= 2)
    ;
  work(1, l);
  work(n - l + 1, n);
  printf("%d\n", top);
  for (int i = (int)(1); i <= (int)(top); i++)
    printf("%d %d\n", ans[i].first, ans[i].second);
}
