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