#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, la, lb, fa, fb, l, r = 0;
int main() {
  cin >> n >> m >> a >> b;
  fa = (m - a % m + 1) % m;
  fb = b % m;
  if (b == n) fb = 0;
  la = a / m;
  if (a % m == 0) la--;
  lb = b / m;
  if (b % m == 0) lb--;
  if (lb == la)
    cout << "1" << endl;
  else if (lb == la + 1)
    if (fa == 0 && fb == 0)
      cout << "1" << endl;
    else
      cout << "2" << endl;
  else {
    if (fa != 0) r++;
    if (fb != 0) r++;
    if (fa + fb == m)
      cout << r << endl;
    else
      cout << ++r << endl;
  }
  return 0;
}
