#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
vector<pair<long long int, long long int>> ans;
void solve(long long int l, long long int r) {
  long long int len = r - l;
  long long int off = l;
  long long int p = 1;
  while (p < len) {
    set<long long int> used;
    for (long long int i = l; i < r; ++i) {
      if (used.count(i)) continue;
      ans.push_back({i, i + p});
      used.insert(i + p);
    }
    p *= 2;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  if (__builtin_popcount(n) == 1)
    solve(0, n);
  else {
    long long int f = (1ll) << (63 - __builtin_clzll(n));
    solve(0, f);
    solve(n - f, n);
  }
  cout << ans.size() << endl;
  for (auto o : ans) cout << o.first + 1 << " " << o.second + 1 << '\n';
}
