#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int main() {
  while (scanf("%d%d%d%d", &n, &m, &a, &b) != EOF) {
    if (m == 1) {
      cout << 1 << endl;
    } else if ((a - 1) / m == (b - 1) / m) {
      cout << 1 << endl;
    } else if ((b == n || b % m == 0) && a % m == 1) {
      cout << 1 << endl;
    } else if ((a - 1) / m + 1 == (b - 1) / m) {
      cout << 2 << endl;
    } else if ((a - 1) % m == (b - 1) % m + 1) {
      cout << 2 << endl;
    } else if (b == n || b % m == 0 || a % m == 1) {
      cout << 2 << endl;
    } else
      cout << 3 << endl;
  }
  return 0;
}
