#include <bits/stdc++.h>
using namespace std;
long long i, j, a, b, n, m, str, stra, strb, raz, k, pa = 1, pb = 1;
int main() {
  cin >> m >> n >> a >> b;
  if (m % n == 0)
    str = m / n;
  else
    str = m / n + 1;
  if (a % n == 0)
    stra = a / n;
  else
    stra = a / n + 1;
  if (b % n == 0)
    strb = b / n;
  else
    strb = b / n + 1;
  if (a == (stra - 1) * n + 1) pa = 0;
  if (b == strb * n || b == m) pb = 0;
  if (pa + pb == 2) {
    if (a % n == (b % n + 1) % n) pa = 0;
  }
  if (stra == strb - 1 && pa && pb) {
    cout << 2;
    return 0;
  }
  if (stra == strb) {
    cout << 1;
    return 0;
  }
  cout << pa + pb + 1;
  return 0;
}
