#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> ans;
int main() {
  long long i, j, k, s, d, r, m, n;
  cin >> n;
  m = 1;
  while (m * 2 <= n) m *= 2;
  if (m == 1) {
    cout << "0\n";
    return 0;
  }
  s = 0;
  for (i = m; i > 1; i /= 2) {
    for (j = 1; j <= m; j += i) {
      long long x = j, y = j + i / 2;
      while (x < j + i / 2) ans.push_back({x++, y++});
    }
  }
  r = n - m;
  for (i = m; i > 1; i /= 2) {
    for (j = 1; j <= m; j += i) {
      long long x = j + r, y = j + r + i / 2;
      while (x < j + r + i / 2) ans.push_back({x++, y++});
    }
  }
  cout << ans.size() << endl;
  for (i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
}
