#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f;
const double eps = (1e-10);
int n, m, a, b;
int main() {
  ios::sync_with_stdio(false);
  cout.precision(3);
  cin >> n >> m >> a >> b;
  --a, --b;
  if ((abs(a - b) + 1 <= m && a % m <= b % m) ||
      (a % m == 0 && (b % m == (m - 1) || b + 1 == n))) {
    cout << 1;
    return 0;
  }
  if (a % m == (b % m) + 1 ||
      (abs(a - b) + 1 <= (m - (a % m)) + ((b % m) + 1))) {
    cout << 2;
    return 0;
  }
  int ans = 1;
  if (a % m != 0) ++ans;
  if (b % m != m - 1 && b + 1 != n) ++ans;
  cout << ans;
  return 0;
}
