#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ans;
inline int read() {
  register int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
void solve(int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1;
  solve(l, mid);
  solve(mid + 1, r);
  for (int i = 0; l + i <= mid; i++)
    ans.push_back(make_pair(l + i, mid + i + 1));
}
signed main() {
  int n = read();
  int h = log2(n);
  solve(1, 1 << h);
  solve(n - (1 << h) + 1, n);
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << ' ' << ans[i].second << endl;
}
