#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  double ad = a, bd = b, md = m;
  if (ceil(ad / md) == ceil(bd / md)) return cout << 1, 0;
  if ((a - 1) % m == 0 && (b % m == 0 || b == n)) return cout << 1, 0;
  if ((b % m == 0 || b == n)) return cout << 2, 0;
  if ((a - 1) % m == 0) return cout << 2, 0;
  if (ceil(bd / md) - ceil(ad / md) == 1) return cout << 2, 0;
  if ((a % m == 0 && b % m == m - 1) || (a % m - b % m == 1))
    return cout << 2, 0;
  return cout << 3, 0;
}
