#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
int lim, m;
int fuckyou(int x) {
  int res = 1;
  while (res < x) res <<= 1;
  res >>= 1;
  return res;
}
vector<pair<int, int> > ans;
void solve(int opt) {
  for (register int len = 1; len < lim; len <<= 1) {
    for (register int i = 0; i < lim; i += len << 1) {
      for (register int j = 0; j < len; j++) {
        int x = i + j, y = i + j + len;
        bool flag = (x > m) || (y > m);
        if (!flag) {
          if (opt == 0) {
            ans.push_back({x + 1, y + 1});
          } else {
            ans.push_back({m - x, m - y});
          }
        }
      }
    }
  }
}
int main() {
  scanf("%d", &m);
  lim = fuckyou(m);
  solve(0), solve(1);
  printf("%d\n", ans.size());
  for (auto v : ans) printf("%d %d\n", v.first, v.second);
  return 0;
}
