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