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