#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  if ((a - 1) / m == (b - 1) / m) {
    printf("1");
    return 0;
  }
  static int c1, c2;
  if ((a - 1) % m != 0) c1 = m - (a - 1) % m;
  if (b % m != 0) c2 = b % m;
  if (c1 == 0 && b == n) {
    printf("1");
    return 0;
  }
  if (c1 == 0 && c2 == 0) {
    printf("1");
    return 0;
  }
  if (b == n) {
    printf("2");
    return 0;
  }
  if (c1 + c2 == m) {
    cout << 2;
    return 0;
  }
  cout << (int)(c1 >= 1) + (int)(c2 >= 1) + (int)((b - a + 1 - c1 - c2) >= 1);
  return 0;
}
