#include <bits/stdc++.h>
using namespace std;
int N;
vector<pair<int, int>> ans, packs;
void sp2(int st, int n) {
  if (n < 2) return;
  sp2(st, n / 2);
  sp2(st + n / 2, n / 2);
  for (int i = 0; i < n / 2; ++i) {
    ans.push_back({st + i, st + n / 2 + i});
  }
}
void getp0(int st, int now, int need) {
  while (now < need) {
    for (int i = 0; i < now; ++i) {
      ans.push_back({st + i, st + now + i});
    }
    now *= 2;
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  N = n;
  for (int t = 16384, u = 0; t > 0; t /= 2) {
    if (n & t) {
      sp2(u, t);
      packs.push_back({u, t});
      u += t;
    }
  }
  int p0 = 0;
  while (packs.size() > 2) {
    int psz = packs.size();
    getp0(packs.back().first, packs.back().second, packs[psz - 2].second);
    packs.pop_back();
    int nsz = packs.back().second, nst = packs.back().first;
    packs.back().second *= 2;
    for (int i = 0; i < nsz; ++i) {
      ans.push_back({nst + i, nst + nsz + i});
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << (ans[i].first % n) + 1 << " " << (ans[i].second % n) + 1 << "\n";
  }
}
