#include <bits/stdc++.h>
const int inf = (1 << 30) - 1;
const double eps = 1e-9;
using namespace std;
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  int ans = 0;
  if (a > b) swap(a, b);
  int x1 = (a - 1) / m + 1;
  int x2 = (b - 1) / m + 1;
  int y1 = ((a - 1) % m) + 1;
  int y2 = ((b - 1) % m) + 1;
  if (b == n) y2 = m;
  if (x1 == x2) {
    cout << "1" << endl;
    return 0;
  } else if (x1 + 1 == x2) {
    if (y1 == 1 && y2 == m)
      cout << "1" << endl;
    else
      cout << "2" << endl;
    return 0;
  }
  if (y1 == y2 + 1) {
    cout << "2";
    return 0;
  }
  ans = 1;
  if (y1 != 1) ans++;
  if (y2 != m) ans++;
  cout << ans;
  return 0;
}
