#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int tot, n, lg[N];
struct stu {
  int x, y;
  stu(int x = 0, int y = 0) : x(x), y(y) {}
};
stu ans[N];
void sol(int x, int y) {
  if (x == y) return;
  int mid = (x + y) / 2;
  sol(x, mid);
  sol(mid + 1, y);
  for (int i = x; i <= mid; i++) ans[++tot] = stu(i, i - x + mid + 1);
}
int main() {
  lg[1] = 1;
  for (int i = 2; i <= 1000000; i++) lg[i] = lg[i >> 1] << 1;
  cin >> n;
  sol(1, lg[n]);
  sol(n - lg[n] + 1, n);
  cout << tot << endl;
  for (int i = 1; i <= tot; i++) cout << ans[i].x << " " << ans[i].y << endl;
  return 0;
}
