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