#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  a--;
  b--;
  int ra, ca, rb, cb;
  ra = a / m;
  ca = a % m;
  rb = b / m;
  cb = b % m;
  if (ra == rb)
    cout << "1";
  else {
    if (ca == 0 && cb == m - 1)
      cout << "1";
    else if (ca == 0 && b == n - 1)
      cout << 1;
    else if (ca == 0)
      cout << 2;
    else if (cb == m - 1)
      cout << 2;
    else {
      if (b == n - 1)
        cout << 2;
      else if (rb - ra > 1) {
        if (ca - 1 == cb)
          cout << 2;
        else
          cout << 3;
      } else
        cout << 2;
    }
  }
  cout << endl;
  return 0;
}
