#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, l1, l2, num1, num2;
int main() {
  cin >> n >> m >> a >> b;
  a--;
  b--;
  l1 = a / m;
  l2 = b / m;
  num1 = a % m;
  num2 = b % m;
  int ans = 1;
  if (l2 - l1 != 0) {
    if (num1 != 0) {
      ans++;
      if (b == n - 1 || num1 - 1 == num2) {
        cout << ans;
        return 0;
      }
    }
    if (l2 - l1 > 1 && num2 != m - 1 && b != n - 1) ans++;
  }
  cout << ans;
  return 0;
}
