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