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