#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n, m, a, b;
int get() {
  if (a / m == b / m) return 1;
  int up = m - a % m;
  int down = b % m + 1;
  if (b == n - 1) {
    b += m - down;
    down = m;
  }
  int f1 = a + up;
  int f2 = ((b + 1) % m == 0) ? b : b - down;
  int middle = (f2 - f1 + 1) / m;
  if (up == m && down == m) return 1;
  if ((up + down) % m == 0) return 2;
  if (middle <= 0) return 2;
  if (up == m || down == m) return 2;
  return 3;
}
void solution() {
  cin >> n >> m >> a >> b;
  a--, b--;
  int ret = get();
  cout << ret << endl;
}
int main() {
  solution();
  return 0;
}
