#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  int x = (a - a / m * m == 0 ? a / m : a / m + 1);
  int y = (b - b / m * m == 0 ? b / m : b / m + 1);
  if (x == y or m == 1) {
    cout << 1;
    return 0;
  }
  if (a - a / m * m == 1 and b - b / m * m == 0) {
    cout << 1;
    return 0;
  }
  if (a - a / m * m == 1 and b == n) {
    cout << 1;
    return 0;
  }
  if (b == n and a - a / m * m != 1) {
    cout << 2;
    return 0;
  }
  if (y * m - b - x * m + a == 1) {
    cout << 2;
    return 0;
  }
  if (y - x == 1 and
      (a - a / m * m != 1 or (a - a / m * m == 1 and b - b / m * m != 0))) {
    cout << 2;
    return 0;
  }
  if (y - x != 0 and b - b / m * m == 0 and a - a / m * m != 1) {
    cout << 2;
    return 0;
  }
  if (y - x != 0 and a - a / m * m == 1 and b - b / m * m != 0) {
    cout << 2;
    return 0;
  }
  cout << 3;
  return 0;
}
