#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3f;
const int N = 1e5 + 10;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  --a;
  --b;
  int r1 = a / m, c1 = a % m, r2 = b / m, c2 = b % m;
  if (r1 == r2) {
    cout << 1 << '\n';
    return 0;
  }
  if (c1 == 0) {
    if (c2 == m - 1 || b == n - 1) {
      cout << 1 << '\n';
      return 0;
    }
    cout << 2 << '\n';
    return 0;
  }
  if (r2 - r1 == 1 || c2 == c1 - 1 || b == n - 1 || c2 == m - 1) {
    cout << 2 << '\n';
    return 0;
  }
  cout << 3 << '\n';
  return 0;
}
