#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  int ans = 3;
  if (a % m == 1 && b % m == 0) {
    ans = min(ans, 1);
  }
  if (a % m == 1 || b % m == 0) {
    ans = min(ans, 2);
  }
  int bf = (a - 1) / m;
  int bs = (b - 1) / m;
  if (bf == bs) {
    ans = min(ans, 1);
  }
  if (bf + 1 == bs) {
    ans = min(ans, 2);
  }
  if (a % m == 1 && b == n) {
    ans = min(ans, 1);
  }
  if (b == n) {
    ans = min(ans, 2);
  }
  int p1 = (a - 1) % m;
  int p2 = (b - 1) % m;
  if (p1 == p2 + 1) {
    ans = min(ans, 2);
  }
  if (m == 1) {
    ans = min(ans, 1);
  }
  cout << ans;
}
