#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  while (cin >> n >> m >> a >> b) {
    a--;
    b--;
    int r1 = a / m, r2 = b / m;
    int c1 = a % m, c2 = b % m;
    if (r1 == r2)
      cout << 1 << endl;
    else if (c1 == 0 && c2 == m - 1)
      cout << 1 << endl;
    else if (c1 == 0 && c2 != m - 1) {
      if (b == n - 1)
        cout << 1 << endl;
      else
        cout << 2 << endl;
    } else if (r1 + 1 == r2)
      cout << 2 << endl;
    else if (c1 != 0 && c2 == m - 1)
      cout << 2 << endl;
    else {
      if (b == n - 1)
        cout << 2 << endl;
      else if (c2 + 1 == c1)
        cout << 2 << endl;
      else
        cout << 3 << endl;
    }
  }
  return 0;
}
