#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  while (cin >> n >> m >> a >> b) {
    a--;
    b--;
    int oa, pa, ob, pb;
    oa = a / m;
    pa = a % m;
    ob = b / m;
    pb = b % m;
    if (b == n - 1) {
      pb = m - 1;
    }
    if (oa == ob) {
      cout << "1";
      continue;
    }
    if (pa == 0 && pb == m - 1) {
      cout << "1";
      continue;
    }
    if (pa - pb == 1) {
      cout << "2";
      continue;
    }
    int hang = ob - oa;
    if (pa > 0 && pb < m - 1) {
      if (hang == 1) {
        cout << "2";
        continue;
      } else {
        cout << "3";
        continue;
      }
    }
    cout << "2";
  }
}
