#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(
    chrono::high_resolution_clock::now().time_since_epoch().count());
const int INF = 2e9;
const long long ML = 4e18;
vector<pair<int, int> > ans;
void dfs(int l, int r) {
  if (l == r) return;
  int len = r - l + 1;
  dfs(l, l + len / 2 - 1);
  dfs(l + len / 2, r);
  int i = l, j = r;
  while (i < j) {
    ans.push_back({i++, j--});
  }
}
void solve() {
  int n;
  cin >> n;
  int m = 1;
  while (m * 2 <= n) m *= 2;
  dfs(1, m);
  int p = n - m;
  dfs(p + 1, n);
  cout << ans.size() << endl;
  for (auto t : ans) cout << t.first << " " << t.second << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
