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