#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k;
  int n, m, a, b;
  int x1, y1, x2, y2;
  while (scanf("%d%d%d%d", &n, &m, &a, &b) != EOF) {
    if (a % m == 0) {
      x1 = a / m;
      y1 = m;
    } else {
      x1 = a / m + 1;
      y1 = a % m;
    }
    if (b % m == 0) {
      x2 = b / m;
      y2 = m;
    } else {
      x2 = b / m + 1;
      y2 = b % m;
    }
    if (a == n) y1 = m;
    if (b == n) y2 = m;
    if (x1 == x2 || (y1 == 1 && y2 == m))
      printf("1\n");
    else if (y1 == 1 || y2 == m || (y1 == y2 + 1) || (x1 + 1 == x2))
      printf("2\n");
    else
      printf("3\n");
  }
  return 0;
}
