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