#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, m, n, rstart, rend, cstart, cend;
  scanf("%d %d %d %d", &n, &m, &a, &b);
  if ((m >= n) || (m == 1))
    printf("1\n");
  else {
    rstart = (a / m) + 1;
    if ((a % m) == 0) --rstart;
    cstart = a - ((rstart - 1) * m);
    rend = (b / m) + 1;
    if ((b % m) == 0) --rend;
    cend = b - ((rend - 1) * m);
    if (((cstart == 1) && ((cend == m) || (b == n))) || (rstart == rend) ||
        ((a == 1) && (b == n)))
      printf("1\n");
    else {
      if (((cstart != 1) && ((cend == m) || (b == n))) ||
          ((cstart == 1) && (cend != m)))
        printf("2\n");
      else if ((rend - rstart) == 1)
        printf("2\n");
      else if ((cstart - cend) == 1)
        printf("2\n");
      else
        printf("3\n");
    }
  }
  return 0;
}
