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