#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > ans;
int log(long long x) { return 64 - __builtin_clzll(x) - 1; }
void solve(long long int l, long long int r) {
  if (r - l == 1) {
    ans.push_back({l, r});
    return;
  }
  long long int mid = r - (r - l + 1) / 2;
  solve(l, mid);
  solve(mid + 1, r);
  for (long long int i = mid; i >= l; i--) ans.push_back({i, r - (i - l)});
}
int main() {
  long long int n;
  cin >> n;
  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }
  long long int k = log(n);
  long long int x = 1;
  for (long long int i = 1; i <= k; i++) x *= 2;
  solve(1, x);
  if (n != x) solve(n - x + 1, n);
  cout << ans.size() << "\n";
  for (long long int i = 0; i <= ans.size() - 1; i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
}
