#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct outputer;
struct outputable {};
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 15000;
struct Input {
  int n;
  bool read() { return !!(cin >> n); }
  void init(const Input& input) { *this = input; }
};
struct Data : Input {
  vector<pair<int, int> > ans;
  void write() {
    cout << ((int)(ans).size()) << endl;
    for (int i = int(0); i < int(((int)(ans).size())); ++i) {
      printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
    }
  }
};
namespace Main {
struct Solution : Data {
  void make(int l, int r, int step) {
    assert((r - l) % step == 0);
    int k = (r - l) / step;
    assert((k & (k - 1)) == 0);
    if (k == 1) {
      return;
    }
    for (int i = int(0); i < int(k / 2); ++i) {
      ans.emplace_back(make_pair(l + 2 * i * step, l + (2 * i + 1) * step));
    }
    make(l, r, 2 * step);
    make(l + step, r + step, 2 * step);
  }
  void solve() {
    int m = 1;
    while (2 * m < n) {
      m *= 2;
    };
    ;
    make(0, m, 1);
    make(n - m, n, 1);
  }
  void clear() { *this = Solution(); }
};
}  // namespace Main
Main::Solution sol;
int main() {
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  sol.read();
  sol.solve();
  sol.write();
  return 0;
}
