#include <bits/stdc++.h>
using namespace std;
int N, M, T;
int main() {
  int i, j, k;
  int a, b;
  scanf("%d%d%d%d", &N, &M, &a, &b);
  int x = a % M, y = b % M;
  if (M == 1 || (x == 1 && b == N))
    printf("1\n");
  else if ((a - 1) / M == (b - 1) / M)
    printf("1\n");
  else if (abs((a - 1) / M - (b - 1) / M) == 1) {
    if (x == 1 && y == 0)
      printf("1\n");
    else
      printf("2\n");
  } else if (b == N) {
    if (x == 1)
      printf("1\n");
    else
      printf("2\n");
  } else {
    if (x == 1 && y == 0)
      printf("1\n");
    else if (x - y == 1 || (x == 0 && y == M - 1) || (y == 0) || x == 1)
      printf("2\n");
    else
      printf("3\n");
  }
  scanf(" ");
}
