#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, n, m, w, h, x1, y1, x2, y2;
  cin >> n >> m >> a >> b;
  w = m;
  h = n / m;
  if (n % m) h++;
  x1 = a / w + 1;
  if (a % w == 0) x1--;
  y1 = a % w;
  if (y1 == 0) y1 = w;
  x2 = b / w + 1;
  if (b % w == 0) x2--;
  y2 = b % w;
  if (y2 == 0) y2 = w;
  if (x1 == x2 || a == 1 && b == n) {
    cout << 1;
    return 0;
  }
  if (y1 == 1 && y2 == w) {
    cout << 1;
    return 0;
  }
  if (b == n && y1 == 1) {
    cout << 1;
    return 0;
  }
  if (a == 1 && y2 == w) {
    cout << 1;
    return 0;
  }
  if (a == 1 || b == n) {
    cout << 2;
    return 0;
  }
  if (y1 == 1 || y2 == w) {
    cout << 2;
    return 0;
  }
  if (y1 - y2 == 1) {
    cout << 2;
    return 0;
  }
  if (abs(x1 - x2) == 1) {
    cout << 2;
    return 0;
  }
  cout << 3;
  return 0;
}
