#include <bits/stdc++.h>
using namespace std;
long long i, i1, j, k, k1, t, n, m, res, flag[10], a, b, p2;
vector<array<long long, 2>> sl;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  k = 1;
  while (2 * k <= n) k *= 2;
  for (p2 = 2; p2 <= k; p2 *= 2) {
    for (i = 0; i < k; i++) {
      if ((i % p2) < (p2 / 2)) sl.push_back({i + 1, i + p2 / 2 + 1});
    }
  }
  for (p2 = 2; p2 <= k; p2 *= 2) {
    for (i = 0; i < k; i++) {
      if ((i % p2) < (p2 / 2))
        sl.push_back({i + n - k + 1, i + p2 / 2 + n - k + 1});
    }
  }
  cout << sl.size() << "\n";
  for (auto u : sl) cout << u[0] << ' ' << u[1] << "\n";
  return 0;
}
