#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  int ans = 3;
  if (a % m == 1) ans--;
  if (b == n || b % m == 0 || (b - a + 1) % m == 0) ans--;
  cout << min(m, min(ans, (b - 1) / m - (a - 1) / m + 1));
  return 0;
}
