#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> ans;
void gogo(int n, int pre) {
  for (int offset = 1; offset < n; offset *= 2)
    for (int i = 1; i + offset <= n; i += offset << 1)
      for (int j = 0; j < offset; j++)
        ans.emplace_back(pre + i + j, pre + i + j + offset);
}
void test_case() {
  int n, k;
  cin >> n;
  k = n - 1;
  k |= k >> 1;
  k |= k >> 2;
  k |= k >> 4;
  k |= k >> 8;
  k |= k >> 16;
  ++k;
  k >>= 1;
  gogo(k, 0);
  gogo(k, n - k);
  int len = ans.size();
  cout << len << '\n';
  for (int i = 0; i < len; i++)
    cout << ans[i].first << ' ' << ans[i].second << '\n';
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int Case = 1;
  for (int i = 0; i < Case; i++) {
    test_case();
  }
  return 0;
}
