#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
vector<pair<long long, long long> > ans;
void dfs(long long l, long long r) {
  if ((r - l) != 1) {
    long long mid = (l + r) / 2;
    dfs(l, mid);
    dfs(mid, r);
    for (long long i = l; i < mid; ++i) {
      ans.emplace_back(i, i + (r - l) / 2);
    }
  }
}
void solve() {
  long long n;
  cin >> n;
  long long k = 1;
  while (k <= n) k <<= 1;
  k >>= 1;
  dfs(0, k);
  dfs(n - k, n);
  cout << ans.size() << endl;
  for (long long i = 0; i < (long long)ans.size(); i++) {
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
