#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> ans;
void boo(const long long &k, const long long &start) {
  if (k == 0) return;
  boo(k - 1, start);
  boo(k - 1, start + (1 << (k - 1)));
  for (long long i = 0; i < (1 << (k - 1)); ++i)
    ans.emplace_back(start + i, start + (1 << (k - 1)) + i);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout << fixed << setprecision(15);
  long long n;
  cin >> n;
  long long k = 0;
  while ((1 << k) <= n) ++k;
  --k;
  boo(k, 1);
  boo(k, n - (1 << k) + 1);
  cout << ans.size() << '\n';
  for (auto &[x, y] : ans) cout << x << ' ' << y << '\n';
  return 0;
}
