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