#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &first, T second) {
  first < second ? first = second : T();
}
template <typename T>
void chkmin(T &first, T second) {
  first > second ? first = second : T();
}
template <typename T>
void readint(T &first) {
  first = 0;
  int f = 1;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) first = first * 10 + c - '0';
  first *= f;
}
const int MOD = 998244353;
inline int dmy(int first) { return first >= MOD ? first - MOD : first; }
inline void inc(int &first, int second) { first = dmy(first + second); }
int qmi(int first, int second) {
  int ans = 1;
  for (; second; second >>= 1, first = 1ll * first * first % MOD)
    if (second & 1) ans = 1ll * ans * first % MOD;
  return ans;
}
const int MAXN = 15005;
int n, k;
void work(int l) {
  for (int i = 0; i < k; ++i)
    for (int j = 0; j < (1 << k); ++j)
      if (!(j & (1 << i))) printf("%d %d\n", l + j, l + (j ^ (1 << i)));
}
int main() {
  readint(n);
  for (k = 0; (1 << (k + 1)) <= n; ++k)
    ;
  printf("%d\n", k * (1 << k));
  work(1), work(n - (1 << k) + 1);
  return 0;
}
