#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  if (m == 1 || (a == 1 && b == n)) {
    cout << 1 << endl;
    return 0;
  }
  if ((b - a + 1) % m == 0) {
    if (a % m == 1)
      cout << 1 << endl;
    else
      cout << 2 << endl;
    return 0;
  }
  if ((a - 1) / m == (b - 1) / m) {
    cout << '1' << endl;
    return 0;
  }
  int ans = 0;
  if ((a % m) != 1) ans++;
  if ((b % m) != 0 && (b != n || b / m - ((a == 1) ? (-1) : ((a - 2) / m)) < 2))
    ans++;
  if (b / m - ((a == 1) ? (-1) : ((a - 2) / m)) >= 2) ans++;
  cout << ans << endl;
  return 0;
}
