#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int main() {
  int n;
  scanf("%d", &n);
  int k = min(n, (int)log2(n));
  vector<pair<int, int> > ans;
  int R = (1 << k), L = n - (1 << k) + 1;
  for (int i = 0; i <= k; i++) {
    int num = 1 << i;
    for (int j = 1; j <= (1 << k); j += num * 2) {
      for (int ci = j; ci <= j + num - 1; ci++) {
        int cj = ci + num;
        if (cj > R) break;
        ans.push_back({ci, cj});
      }
    }
  }
  if (n != (1 << k)) {
    for (int i = 0; i <= k; i++) {
      int num = 1 << i;
      for (int j = n; j >= n - (1 << k) + 1; j -= num * 2) {
        for (int ci = j; ci >= j - num + 1; ci--) {
          int cj = ci - num;
          if (cj < L) break;
          ans.push_back({ci, cj});
        }
      }
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) {
    printf("%d %d\n", ans[i].first, ans[i].second);
  }
  return 0;
}
