#include <bits/stdc++.h>
struct point {
  int x;
  int y;
};
point loc(int m, int a) {
  point res;
  res.x = a / m;
  res.y = a % m;
  if (res.y == 0) res.x--;
  return res;
}
int main() {
  int n, m, a, b;
  while (scanf("%d%d%d%d", &n, &m, &a, &b) != EOF) {
    point st, ed;
    st = loc(m, a);
    ed = loc(m, b);
    if (m == 1)
      printf("1\n");
    else if (st.y == 1 && (ed.y == 0 || b == n))
      printf("1\n");
    else if (st.x == ed.x)
      printf("1\n");
    else if (m == 2)
      printf("2\n");
    else if (st.x + 1 == ed.x)
      printf("2\n");
    else if (st.y == 1 || ed.y == 0 || b == n)
      printf("2\n");
    else if (st.y - 1 == ed.y || (st.y == 0 && ed.y == m - 1))
      printf("2\n");
    else if (ed.y == 0)
      printf("2\n");
    else
      printf("3\n");
  }
}
