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