#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, x, y, z, ans1, ans2, g, h, f;
int main() {
  cin >> n >> m >> a >> b;
  if (a > m) {
    if (a % m == 0)
      ans1 = a / m;
    else
      ans1 = a / m + 1;
  } else
    ans1 = 1;
  if (b > m) {
    if (b % m == 0)
      ans2 = b / m;
    else
      ans2 = b / m + 1;
  } else
    ans2 = 1;
  if (ans1 == ans2) {
    cout << 1;
    return 0;
  }
  if ((a == 1 || (a - 1) % m == 0) && (b == n || b % m == 0))
    f = 1;
  else if ((a == 1 || (a - 1) % m == 0))
    f = 2;
  else if ((b == n || b % m == 0))
    f = 2;
  else if (ans2 - ans1 == 1)
    f = 2;
  else {
    x = ans1 * m - a + 1;
    y = ans2 * m - b + 1;
    if (x + 1 == y)
      f = 2;
    else
      f = 3;
  }
  cout << f;
  return 0;
}
