#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 0x3f3f3f3f;
vector<pair<int, int> > ope;
void work(int delta, int n) {
  for (int i = 1; i <= n / 2; i <<= 1) {
    for (int j = 1; j <= n; j += i + i) {
      for (int k = j; k <= j + i - 1; k++) {
        ope.push_back(make_pair(k + delta + i, k + delta));
      }
    }
  }
}
int n;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  if (n <= 2) {
    cout << 0 << endl;
    return 0;
  }
  int is = 1;
  while (is * 2 < n) is <<= 1;
  work(0, is);
  work(n - is, is);
  cout << ope.size() << endl;
  for (auto it : ope) cout << it.first << " " << it.second << endl;
  return 0;
}
