#include <bits/stdc++.h>
using namespace std;
int N, M, A, B;
int main() {
  scanf("%d%d%d%d", &N, &M, &A, &B);
  int rA = (A - 1) / M + 1, cA = A - (rA - 1) * M;
  int rB = (B - 1) / M + 1, cB = B - (rB - 1) * M;
  if (B == N) cB = M;
  if (rA == rB) {
    puts("1");
    exit(0);
  }
  if (rA + 1 == rB) {
    if (cA == 1 && cB == M)
      puts("1");
    else
      puts("2");
    exit(0);
  }
  int fA = (cA == 1);
  int fB = (cB == M);
  if (fA + fB) {
    printf("%d\n", 3 - fA - fB);
    exit(0);
  }
  if (cB + 1 == cA)
    puts("2");
  else
    puts("3");
  return 0;
}
