#include <bits/stdc++.h>
using namespace std;
vector<long long int> v, w[16];
void f(long long int s, long long int n) {
  if (n == 2) {
    v.push_back(s + 1);
    v.push_back(s + 2);
    return;
  }
  long long int p = n / 2;
  long long int q = n - p;
  if (p > 1) f(s, p);
  if (q > 1) f(s + p, q);
  for (long long int i = 1; i <= p; i++) {
    v.push_back(s + i);
    v.push_back(s + p + i);
  }
  return;
}
int main() {
  long long int n;
  cin >> n;
  long long int g = n, l = 15, r = 1, m = 0;
  while (g) {
    long long int k = (1 << l);
    if (k <= g) {
      m = max(m, l);
      g -= k;
      f(r - 1, k);
      for (long long int i = 0; i < k; i++) {
        w[l].push_back(r);
        r++;
      }
    }
    l--;
  }
  for (long long int i = 0; i < m; i++) {
    if (w[i].size()) {
      long long int k = (1 << i);
      if (w[i].size() == k) {
        for (long long int j = 0; j < k; j++) {
          w[i].push_back(w[m][0]);
          w[m].erase(w[m].begin());
        }
      }
      for (long long int j = 0; j < k; j++) {
        v.push_back(w[i][j]);
        v.push_back(w[i][k + j]);
      }
      for (long long int j = 0; j < k + k; j++) {
        w[i + 1].push_back(w[i][j]);
      }
    }
  }
  long long int ss = v.size();
  ss /= 2;
  cout << ss << endl;
  for (long long int i = 0; i < ss + ss; i += 2) {
    printf("%lld %lld\n", v[i], v[i + 1]);
  }
}
