#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p);
template <class T>
ostream &operator<<(ostream &os, vector<T> &v);
template <class T>
ostream &operator<<(ostream &os, set<T> &v);
inline void optimizeIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
const int nmax = 2e5 + 7;
void solveTC() {
  int n;
  cin >> n;
  int sz = 1;
  while (sz <= n) {
    sz = sz << 1;
  }
  sz = sz >> 1;
  ;
  vector<pair<int, int> > p;
  for (int add = 1; add <= 15000; add = add << 1) {
    vector<bool> done(n + 1, false);
    for (int i = 1; i <= sz; i++) {
      if (done[i]) continue;
      int j = i + add;
      if (j <= sz)
        p.push_back({i, j});
      else
        break;
      done[i] = true;
      done[j] = true;
    }
  }
  for (int add = 1; add <= 15000; add = add << 1) {
    vector<bool> done(n + 1, false);
    for (int i = n, t = sz; t > 0; i--, t--) {
      if (done[i]) continue;
      int j = i - add;
      if (j > n - sz)
        p.push_back({i, j});
      else
        break;
      done[i] = true;
      done[j] = true;
    }
  }
  int ans = p.size();
  cout << ans << "\n";
  for (auto x : p) {
    cout << x.first << " " << x.second << "\n";
  }
}
int32_t main() {
  optimizeIO();
  int tc = 1;
  while (tc--) {
    solveTC();
  }
  return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
  os << "{" << p.first << ", " << p.second << "} ";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "[ ";
  for (T i : v) {
    os << i << " ";
  }
  os << " ]";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, set<T> &v) {
  os << "[ ";
  for (T i : v) {
    os << i << " ";
  }
  os << " ]";
  return os;
}
