#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int>> ans;
void build(int l, int r) {
  int n = r - l + 1;
  for (int sz = 1; sz < n; sz *= 2) {
    for (int i = l; i < r; i += 2 * sz) {
      for (int j = 0; j < sz; j++) {
        ans.push_back({i + j, i + sz + j});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int k = 0;
  while ((1 << k) <= n) k++;
  k--;
  build(1, (1 << k));
  build(n - (1 << k) + 1, n);
  cout << ans.size() << '\n';
  for (auto it : ans) cout << it.first << ' ' << it.second << '\n';
  return 0;
}
