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