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