#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T>>;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 10;
int n;
vector<pair<int, int>> ans;
void rec(int l, int r) {
  if (l == r) {
    return;
  }
  int mid = (l + r) / 2;
  rec(l, mid);
  rec(mid + 1, r);
  for (int i = 0; i < (int)((r - l + 1) / 2); ++i) {
    ans.emplace_back(l + i, mid + 1 + i);
  }
}
void solve() {
  cin >> n;
  int d = 1;
  while (d * 2 <= n) {
    d *= 2;
  }
  rec(1, d);
  rec(n - d + 1, n);
  cout << (int)ans.size() << "\n";
  for (auto &p : ans) {
    cout << p.first << " " << p.second << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
