#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > ans;
void make(long long l, long long r) {
  if (r - l < 2) return;
  long long m = (l + r) / 2;
  for (long long i = l; i < m; ++i) ans.push_back({i, m + (i - l)});
  make(l, m);
  make(m, r);
}
void solve() {
  long long n;
  cin >> n;
  long long l = 1;
  while (l <= n) {
    l *= 2;
  }
  make(1, l / 2 + 1);
  make(n + 1 - l / 2, n + 1);
  cout << ans.size() << '\n';
  for (long long i = 0; i < ans.size(); ++i)
    cout << ans[i].first << ' ' << ans[i].second << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
