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