#include <bits/stdc++.h>
using namespace std;
int arr[32];
vector<pair<int, int> > ans;
void go(int BIT, int diff) {
  int n = 1 << BIT;
  if (n == 1) return;
  for (int i = 1; i <= n / 2; i++) {
    ans.push_back({i + diff, i + n / 2 + diff});
  }
  go(BIT - 1, diff);
  go(BIT - 1, diff + n / 2);
}
int main() {
  int N;
  scanf("%d", &N);
  if (N <= 2) {
    puts("0");
    return 0;
  }
  for (int i = 14; i >= 0; i--) {
    arr[i] = (N >> i) & 1;
  }
  int maxBIT = 0;
  for (int i = 0; i < 15; i++) {
    if (arr[i]) maxBIT = i;
  }
  if (N == 1 << maxBIT)
    go(maxBIT, 0);
  else {
    go(maxBIT, 0);
    go(maxBIT, N - (1 << maxBIT));
  }
  printf("%d\n", ans.size());
  for (auto i : ans) printf("%d %d\n", i.first, i.second);
  return 0;
}
