#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  long long r1, r2;
  long long c1, c2;
  long long ans;
  if (a % m == 0) {
    r1 = a / m - 1;
    c1 = m - 1;
  } else {
    r1 = a / m;
    c1 = a % m - 1;
  }
  if (b % m == 0) {
    r2 = b / m - 1;
    c2 = m - 1;
  } else {
    r2 = b / m;
    c2 = b % m - 1;
  }
  if (c1 == 0 && c2 == (m - 1)) {
    ans = 1;
  } else {
    if (r1 == r2) {
      ans = 1;
    } else if ((r2 - r1) == 1) {
      ans = 2;
      if (c1 == 0 && b == n) ans = 1;
    } else if ((r2 - r1) > 1) {
      if (c1 == 0) {
        ans = 2;
        if (b == n) ans = ans - 1;
      } else if (c2 == (m - 1))
        ans = 2;
      else if ((c1 - c2) == 1)
        ans = 2;
      else {
        ans = 3;
        if (b == n) ans = ans - 1;
      }
    }
  }
  cout << ans;
}
