#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m, a, b, ans = 0;
  cin >> n >> m >> a >> b;
  bool f1 = (a % m != 1 && a != 1);
  bool f2 = (b % m != 0 && b != n);
  if (m == 1) {
    cout << 1;
    return 0;
  }
  long long apos = a / m;
  long long bpos = b / m;
  if (a % m != 0) {
    apos++;
  }
  if (b % m != 0) {
    bpos++;
  }
  if (apos == bpos) {
    cout << 1;
    return 0;
  }
  if (a == 1 && b == n) {
    cout << 1;
    return 0;
  }
  if (a % m == 1 && b % m == 0 || a % m == 1 && b == n) {
    cout << 1;
    return 0;
  }
  if (bpos - apos == 1) {
    cout << 2;
    return 0;
  }
  if (a % m == 1 && b % m != 0) {
    cout << 2;
    return 0;
  }
  if (b % m == 0 && a % m != 1) {
    cout << 2;
    return 0;
  }
  if (b == n && a % m != 1) {
    cout << 2;
    return 0;
  }
  if ((a % m) - (b % m) == 1 || a % m == 0 && b % m == m - 1) {
    cout << 2;
    return 0;
  }
  cout << 3;
  return 0;
}
