#include <bits/stdc++.h>
int main(void) {
  int n, m, a, b = 1, ans = 3;
  scanf("%d%d%d%d", &n, &m, &a, &b);
  if (a % m == 1 || m == 1) {
    ans--;
  }
  if (b % m == 0 || b == n) {
    ans--;
  }
  if ((b - 1) / m == (a - 1) / m) {
    printf("1");
    return 0;
  }
  if (ans == 3 && (a % m - 1 == b % m || (a % m == 0 && b % m == m - 1) ||
                   (b - 1) / m - (a - 1) / m == 1)) {
    ans--;
  }
  printf("%d", ans);
  return 0;
}
