#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  if (m == 1) {
    cout << "1";
    return 0;
  }
  if (b - a + 1 <= m) {
    long long r = a % m;
    if (!r) r = m;
    if (r + b - a <= m)
      cout << "1";
    else
      cout << "2";
    return 0;
  }
  long long x;
  long long A = a % m;
  if (!A) A = m;
  x = b - a;
  long long B = A + x;
  x++;
  if (A % m == 1) {
    if (B == n || b == n) {
      cout << "1";
    } else if (x < m)
      cout << "1";
    else {
      if (B % m == 0) {
        cout << "1";
      } else
        cout << "2";
    }
    return 0;
  } else {
    if (A % m == 0 && B % m == 0)
      cout << "2";
    else if (B % m == 0) {
      cout << "2";
    } else if (B == n || b == n) {
      cout << "2";
    } else {
      long long r = B % m;
      long long y = x - (m - A + 1 + r);
      if (!y) {
        cout << "2";
      } else if (A % m == B % m + 1) {
        cout << "2";
      } else if (A % m == 0) {
        if (B % m == m - 1)
          cout << "2";
        else
          cout << "3";
      } else
        cout << "3";
    }
  }
  return 0;
}
