#include <bits/stdc++.h>
using namespace std;
struct tp {
  int x, y;
} A, B;
int n, m, a, b;
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  if (b == n) b = n / m * m + (n % m ? m : 0);
  A.x = (a - 1) / m + 1, A.y = (a - 1) % m + 1;
  B.x = (b - 1) / m + 1, B.y = (b - 1) % m + 1;
  if (A.x == B.x)
    puts("1");
  else if (A.y == 1 && B.y == m)
    puts("1");
  else if (A.y == 1 || B.y == m)
    puts("2");
  else if (A.y == B.y + 1)
    puts("2");
  else if (A.x + 1 == B.x)
    puts("2");
  else
    puts("3");
  return 0;
}
