#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e10 + 6;
const long long MOD = 1e9 + 7;
const long long mod = 998244353;
const int MX = 1e6 + 5;
const int LG = 25;
template <typename t>
void fff(const char* x, t&& val1) {
  cout << x << " : " << val1 << "\n";
}
template <typename t1, typename... t2>
void fff(const char* x, t1&& val1, t2&&... val2) {
  const char* xd = strchr(x + 1, ',');
  cout.write(x, xd - x) << " : " << val1 << " | ";
  fff(xd + 1, val2...);
}
vector<pair<long long, long long> > v;
void solve(long long n, long long val) {
  long long p = pow(2, n);
  long long k = 1;
  for (int i = 1; i <= n; i++) {
    k *= 2;
    for (int j = 1; j <= pow(2, n); j += k) {
      for (int l = 0; l < k / 2; l++) {
        v.push_back({j + val + l, j + k / 2 + val + l});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long k = 1;
  while (k < n) {
    k *= 2;
  }
  k /= 2;
  long long j = n - k;
  long long k1 = 1;
  while (k1 < j) {
    k1 *= 2;
  }
  solve(log2(k), 0);
  solve(log2(k1), n - k1);
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
}
