#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b;
bool onhead() { return a % m == 1; }
bool ontail() { return b % m == 0 || b == n; }
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m >> a >> b;
  long long aln = a % m == 0 ? a / m - 1 : a / m;
  long long bln = b % m == 0 ? b / m - 1 : b / m;
  long long ans = 0;
  if (m == 1)
    ans = 1;
  else if (aln == bln)
    ans = 1;
  else {
    if (bln - aln == 1) {
      if (onhead() && ontail())
        ans = 1;
      else
        ans = 2;
    } else {
      if (!onhead() && ontail() || onhead() && !ontail())
        ans = 2;
      else if (onhead() && ontail())
        ans = 1;
      else
        ans = 3;
      if ((b - a + 1) % m == 0) ans = min(ans, 2LL);
    }
  }
  cout << ans;
}
