#include <bits/stdc++.h>
using namespace std;
namespace patch {
template <typename T>
std::string to_string(const T& n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}
}  // namespace patch
const long double PI = 3.14159265358979323846;
long long mdf = 1e+9 + 7;
long double eps = 1e-7;
const long long INF = 3e18 + 1337;
void solve(int cs) {
  int n;
  cin >> n;
  int k = 0;
  int pw = 1;
  while (pw * 2 < n) {
    k++;
    pw *= 2;
  }
  vector<pair<int, int>> ans;
  for (int s = 1; s <= k; s++) {
    for (int i = 0; i < pw; i += (1 << s)) {
      for (int j = 1; j <= (1 << (s - 1)); j++)
        ans.push_back({i + j, i + j + (1 << s - 1)});
    }
  }
  for (int s = 1; s <= k; s++) {
    for (int i = 0; i < pw; i += (1 << s)) {
      for (int j = 1 + n - pw; j <= n - pw + (1 << (s - 1)); j++)
        ans.push_back({i + j, i + j + (1 << s - 1)});
    }
  }
  cout << ans.size() << "\n";
  for (auto p : ans) cout << p.first << " " << p.second << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  srand(time(NULL));
  int q = 1;
  int i = 0;
  while (q--) solve(++i);
  return 0;
}
