#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v;
void work(int l, int r) {
  if (l == r) return;
  int len = r - l + 1;
  int mid = (l + r) / 2;
  work(l, mid);
  work(mid + 1, r);
  for (int i = l; i <= mid; ++i) v.push_back(make_pair(i, i + len / 2));
}
int main() {
  ios::sync_with_stdio(false);
  int n, x;
  cin >> n;
  for (x = 1; x * 2 <= n; x *= 2)
    ;
  work(1, x);
  if (x != n) work(n - x + 1, n);
  cout << v.size() << endl;
  for (auto e : v) {
    cout << e.first << " " << e.second << endl;
  }
  return 0;
}
