#include <bits/stdc++.h>
const int BUFFSIZE = 10240;
char BUFF[BUFFSIZE + 1], *p = BUFF;
int CHAR, SIGN, BYTES = 0;
using namespace std;
int main() {
  int N, M, A, B;
  scanf("%d %d %d %d", &N, &M, &A, &B);
  A -= 1, B -= 1;
  int rows = B / M - A / M + 1;
  if (rows == 1 || M == 1)
    printf("1\n");
  else {
    int AM = A % M, BM = B % M;
    if (B == N - 1) {
      if (AM == 0)
        printf("1\n");
      else
        printf("2\n");
    } else {
      if (AM == 0 && BM == M - 1)
        printf("1\n");
      else if (AM == 0)
        printf("2\n");
      else if (BM == M - 1)
        printf("2\n");
      else if (AM == BM + 1)
        printf("2\n");
      else if (rows == 2)
        printf("2\n");
      else
        printf("3\n");
    }
  }
  return 0;
}
