#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int res;
int linhaa, linhab, colunaa, colunab;
int main() {
  scanf("%d %d %d %d", &n, &m, &a, &b);
  linhaa = (a - 1) / m;
  colunaa = (a - 1) % m;
  linhab = (b - 1) / m;
  colunab = (b - 1) % m;
  if (linhaa == linhab)
    res = 1;
  else {
    if (linhaa == linhab - 1) {
      if (colunaa != 0 or (colunab != m - 1 and b != n))
        res = 2;
      else
        res = 1;
    } else {
      res = 1;
      if (colunaa != 0) res++;
      if (colunab != m - 1 and b != n) res++;
      if (colunab + 1 == colunaa) res = min(res, 2);
    }
  }
  printf("%d\n", res);
  return 0;
}
