#include <bits/stdc++.h>
using namespace std;
const long long int inf = 9e18;
const long double pi = 2 * acos(0.0);
void solve() {
  long long int n;
  cin >> n;
  long long int lim = 1, len;
  for (long long int i = 0; i < 39; ++i) {
    if (lim >= n) {
      lim /= 2;
      len = i - 1;
      break;
    }
    lim *= 2;
  }
  set<long long int> cnt1, cnt2;
  for (long long int i = 1; i < lim + 1; ++i) {
    cnt1.insert(i);
    cnt2.insert(n + 1 - i);
  }
  lim = 1;
  vector<pair<long long int, long long int> > ans;
  for (long long int i = 0; i < len; ++i) {
    set<long long int> temp = cnt1;
    while (!temp.empty()) {
      long long int curr = *(temp.begin());
      temp.erase(curr);
      temp.erase(curr + lim);
      ans.push_back(make_pair(curr, curr + lim));
    }
    lim *= 2;
  }
  lim = 1;
  if (n > 3) {
    for (long long int i = 0; i < len; ++i) {
      set<long long int> temp = cnt2;
      while (!temp.empty()) {
        long long int curr = *(temp.rbegin());
        temp.erase(curr);
        temp.erase(curr - lim);
        ans.push_back(make_pair(curr, curr - lim));
      }
      lim *= 2;
    }
  }
  cout << (int)((ans).size()) << "\n";
  for (auto it : ans) cout << it.first << " " << it.second << "\n";
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int tc = 1;
  while (tc--) {
    solve();
  }
}
