#include <bits/stdc++.h>
using namespace std;
int dcmp(double a, double b) {
  return fabs(a - b) <= 0.00000000000001 ? 0 : (a > b) ? 1 : -1;
}
int main() {
  long long n, m, a, b, cnt = 0, ax, ay, bx, by;
  cin >> n >> m >> a >> b;
  a--;
  b--;
  n--;
  ax = a % m;
  ay = a / m;
  bx = b % m;
  by = b / m;
  if ((ay == by) || (ax == 0 && bx == m - 1) || (ax == 0 && b == n))
    cout << "1";
  else if ((ay + 1 == by) || (ax == 0) || (bx == m - 1) || (b == n) ||
           ((ax - 1 == bx)))
    cout << "2";
  else
    cout << "3";
}
