#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int>> res;
vector<int> merge(vector<int> a, vector<int> b) {
  assert(a.size() == b.size());
  for (int i = 0; i < a.size(); i++) res.push_back({a[i], b[i]});
  vector<int> res(a.begin(), a.end());
  res.insert(res.end(), b.begin(), b.end());
  return res;
}
vector<int> sli(vector<int> &a, int k) {
  assert(a.size() >= k);
  vector<int> res;
  for (int i = 0; i < k; i++) {
    res.push_back(a.back());
    a.pop_back();
  }
  return res;
}
vector<int> prepare(vector<int> a) {
  int n = a.size();
  for (int b = 0; (1 << b) <= n; b++)
    for (int i = 0; i < n; i++)
      if (i >> b & 1) res.push_back({a[i], a[i ^ (1 << b)]});
  return a;
}
int main() {
  while (scanf("%d", &n) == 1) {
    res.clear();
    vector<int> ids(n);
    for (int i = 0; i < n; i++) ids[i] = i;
    vector<vector<int>> ps;
    for (int ib = 0; (1 << ib) <= n; ib++) {
      if ((n >> ib & 1) == 0) continue;
      int np = 1 << ib;
      vector<int> p = prepare(sli(ids, np));
      ps.push_back(p);
    }
    if (ps.size() > 2) {
      reverse(ps.begin(), ps.end());
      vector<int> &a = ps.back();
      for (int i = ps.size() - 2; i >= 1; i--) {
        auto &b = ps[i];
        while (a.size() < b.size()) a = merge(a, sli(ps[0], a.size()));
        a = merge(a, b);
      }
    }
    printf("%lu\n", res.size());
    for (auto &[a, b] : res) printf("%d %d\n", a + 1, b + 1);
    printf("\n");
  }
}
