#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846264338327950288;
int in_c() {
  int c;
  while ((c = getchar()) <= ' ') {
    if (!~c) return ~0;
  }
  return c;
}
int in() {
  int x = 0, c;
  while ((unsigned int)((c = getchar()) - '0') >= 10) {
    if (c == '-') return -in();
    if (!~c) return ~0;
  }
  do {
    x = 10 * x + (c - '0');
  } while ((unsigned int)((c = getchar()) - '0') < 10);
  return x;
}
int main() {
  int N, M, A, B;
  while (cin >> N >> M >> A >> B) {
    --A, --B;
    int sc = A % M;
    int sr = A / M;
    int gc = B % M;
    int gr = B / M;
    if (B == N - 1) gc = M - 1;
    int ans = 0;
    if (sr == gr) {
      ans = 1;
    } else if (sc == 0 && gc == M - 1) {
      ans = 1;
    } else if (sc != 0 && gc == M - 1) {
      ans = 2;
    } else if (sc == 0 && gc != M - 1) {
      ans = 2;
    } else if (sc != 0 && gc != M - 1 && gc == sc - 1) {
      ans = 2;
    } else if (gr == sr + 1) {
      ans = 2;
    } else {
      ans = 3;
    }
    cout << ans << endl;
  }
  return 0;
}
