#include <bits/stdc++.h>
inline int read() {
  int data = 0, w = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
  return data * w;
}
std::vector<std::pair<int, int> > ans;
int n, N;
int main() {
  for (n = read(), N = 1; (N << 1) <= n; N <<= 1)
    ;
  for (int i = 1; i < N; i <<= 1)
    for (int j = 0; j < N; j += (i << 1))
      for (int k = 0; k < i; k++) ans.emplace_back(j + k + 1, i + j + k + 1);
  if (N < n)
    for (int i = 1; i < N; i <<= 1)
      for (int j = 0; j < N; j += (i << 1))
        for (int k = 0; k < i; k++) ans.emplace_back(n - j - k, n - i - j - k);
  printf("%lu\n", ans.size());
  for (auto i : ans) printf("%d %d\n", i.first, i.second);
  return 0;
}
