#include <bits/stdc++.h>
using namespace std;
void precompute(void) {}
int n, m, a, b;
vector<pair<int, int> > nums;
void solve(void) {
  a--, b--, n--;
  int linea = a / m;
  int lineb = b / m;
  int ans;
  if (lineb - linea == 0) {
    cout << 1 << endl;
    return;
  }
  if (m == 1) {
    cout << 1 << endl;
    return;
  }
  int rema = a % m, remb = m - b % m - 1;
  if (rema == 0 && b == n) {
    cout << 1 << endl;
    return;
  }
  if (rema == 0 && remb == 0) {
    cout << 1 << endl;
    return;
  }
  if (lineb - linea == 1) {
    cout << 2 << endl;
    return;
  }
  if (rema + remb == m) {
    cout << 2 << endl;
    return;
  }
  if (rema == 0 || remb == 0) {
    cout << 2 << endl;
    return;
  }
  if (b == n) {
    cout << 2 << endl;
    return;
  }
  cout << 3 << endl;
}
int main() {
  precompute();
  cin >> n >> m >> a >> b;
  solve();
  return 0;
}
