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