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