#include <bits/stdc++.h>
using namespace std;
const long long xxx = 2e6;
const long long maxn = xxx + 5;
const long long inf = 1e9;
const long long mod = 1e9 + 7;
inline void updmin(long long &a, long long b) { a > b ? a = b : 0; }
inline void updmax(long long &a, long long b) { a < b ? a = b : 0; }
long long n;
vector<pair<long long, long long> > vec;
void dfs(long long l, long long r) {
  if (l == r) {
    return;
  }
  long long mid = (l + r) / 2;
  dfs(l, mid);
  dfs(mid + 1, r);
  for (long long i = l; i <= mid; i++) {
    long long j = mid + (i - l) + 1;
    vec.push_back(make_pair(i, j));
  }
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int Cases;
  Cases = 1;
  for (int cas = 1; cas <= Cases; cas++) {
    long long j = 1;
    cin >> n;
    if (n == 1) {
      cout << 0 << "\n";
      return 0;
    }
    while ((j << 1ll) <= n) {
      j <<= 1;
    }
    dfs(1, j);
    dfs(n - j + 1, n);
    cout << vec.size() << "\n";
    for (pair<long long, long long> pl : vec) {
      cout << pl.first << " " << pl.second << "\n";
    }
  }
  return 0;
}
