#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> add_four(vector<pair<int, int>> v, int start) {
  v.push_back(make_pair(start, start + 1));
  v.push_back(make_pair(start + 2, start + 3));
  return v;
}
vector<pair<int, int>> match(vector<pair<int, int>> v, int start, int size1) {
  for (int j = 0; j < size1; j++) {
    v.push_back(make_pair(start + j, start + size1 + j));
  }
  return v;
}
vector<pair<int, int>> give_merge(vector<pair<int, int>> v, int start,
                                  int end) {
  int sz = start / end;
  for (int j = 0; j < sz; j++) {
    for (int k = 0; k < start; k++) {
      v.push_back(make_pair(k + 1, start + k + 1));
    }
  }
  return v;
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  if (n == 1) {
    cout << "1 \n1 1";
  } else if (n == 2 || n == 3) {
    cout << "1 \n1 2";
  } else if (n == 4) {
    cout << "2 \n1 2\n3 4";
  } else {
    long long int tmp1 = log2(n);
    tmp1 = pow(2, tmp1);
    for (int j = 4; j <= tmp1; j = j + 4) {
      v = add_four(v, j - 3);
    }
    for (int sz = 2; sz <= tmp1 / 2; sz = sz * 2) {
      for (int j = 1; j + 2 * sz <= tmp1 + 1; j = j + 2 * sz) {
        v = match(v, j, sz);
      }
    }
    int start1 = n - tmp1 + 1;
    for (int j = start1 + 3; j <= n; j = j + 4) {
      v = add_four(v, j - 3);
    }
    for (int sz = 2; sz <= tmp1 / 2; sz = sz * 2) {
      for (int j = start1; j + 2 * sz <= n + 1; j = j + 2 * sz) {
        v = match(v, j, sz);
      }
    }
    cout << v.size() << "\n";
    int tmp = v.size();
    for (int j = 0; j < tmp; j++) {
      pair<int, int> p = v[j];
      cout << p.first << " " << p.second << "\n";
    }
  }
}
