#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
void merge(int l, int r, int lev) {
  if (lev == 0) {
    ans.push_back({l, r});
    return;
  }
  int mid = (l + r) >> 1;
  merge(l, mid, lev - 1);
  merge(mid + 1, r, lev - 1);
  int j = mid + 1;
  for (int i = l; i <= mid; i++) {
    ans.push_back({i, j});
    j++;
  }
}
int main(int argc, char** argv) {
  int n;
  scanf("%d", &n);
  if (n == 1) {
    printf("0");
    return 0;
  }
  int t = 1;
  int lev = -1;
  while (t * 2 <= n) t *= 2, lev++;
  merge(1, t, lev);
  merge(n - t + 1, n, lev);
  cout << ans.size() << endl;
  for (int i = 0; i <= ans.size() - 1; i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
