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