#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, a, b;
  int x1, y1, x2, y2;
  while (cin >> n >> m >> a >> b) {
    x1 = a / m;
    if (a % m) x1++;
    y1 = a % m;
    if (y1 == 0) y1 = m;
    x2 = b / m;
    if (b % m) x2++;
    y2 = b % m;
    if (y2 == 0) y2 = m;
    int ans;
    if (x1 == x2)
      ans = 1;
    else if (x1 + 1 == x2) {
      if (y1 == 1 && y2 == m)
        ans = 1;
      else {
        if (b == n && y1 == 1)
          ans = 1;
        else
          ans = 2;
      }
    } else {
      ans = 1;
      if (b == n) {
        if (y1 != 1) ans++;
      } else {
        if (y2 + 1 == y1)
          ans++;
        else {
          if (y1 != 1) ans++;
          if (y2 != m) ans++;
        }
      }
    }
    cout << ans << endl;
  }
}
