#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const double pi = acos(-1.0);
template <class T>
T& ls(T& a, T b) {
  if (b < a) a = b;
  return a;
}
template <class T>
T& gs(T& a, T b) {
  if (b > a) a = b;
  return a;
}
inline int to_i(const string& s) {
  int n;
  sscanf(s.c_str(), "%d", &n);
  return n;
}
inline string to_s(int n) {
  char buf[32];
  sprintf(buf, "%d", n);
  return string(buf);
}
int n, m;
int a[10][10];
int main() {
  int i, j, k, a, b;
  scanf("%d%d%d%d", &n, &m, &a, &b);
  {
    int ans = 0;
    if (a > b) swap(a, b);
    a--;
    b--;
    if (b > n) b = n;
    int ra = a / m;
    int rb = b / m;
    int ca = a % m;
    int cb = b % m;
    if (rb == ra || (a == 0 && b == n - 1))
      ans = 1;
    else {
      int len = rb - ra + 1;
      if (ca == 0 && (cb == m - 1 || b == n - 1)) {
        ans = 1;
      } else if (ca == 0 || cb == m - 1) {
        ans = 2;
      } else {
        if (len == 2)
          ans = 2;
        else {
          if (ca == cb + 1)
            ans = 2;
          else if (b == n - 1)
            ans = 2;
          else
            ans = 3;
        }
      }
    }
    printf("%d\n", ans);
  }
}
