#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > q;
void makeEqual(int first, int last) {
  if (first == last) return;
  int mid = (first + last + 1) / 2;
  makeEqual(first, mid - 1);
  makeEqual(mid, last);
  for (int i = first; i < mid; ++i) {
    q.emplace_back(i, i + mid - first);
  }
}
int main() {
  int n;
  cin >> n;
  int pow2 = 1;
  while (pow2 * 2 < n) pow2 <<= 1;
  makeEqual(1, pow2);
  makeEqual(n - pow2 + 1, n);
  cout << q.size() << endl;
  for (auto qr : q) cout << qr.first << ' ' << qr.second << endl;
  return 0;
}
