#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  if (m == 1)
    printf("1\n");
  else if ((a - 1) / m == (b - 1) / m)
    printf("1\n");
  else if (b == n) {
    if (a % m == 1)
      printf("1\n");
    else
      printf("2\n");
  } else {
    int ans = 1;
    if (a % m != 1) ++ans;
    if (b % m != 0) ++ans;
    if ((a - 1) / m == (b - 1) / m - 1) ans = min(ans, 2);
    int na = (a - 1) % m;
    int nb = (b - 1) % m;
    if (na == nb + 1) ans = min(ans, 2);
    printf("%d\n", ans);
  }
  return 0;
}
