#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const long long MOD = 998244353;
long long n, T, m, k, res;
long long buf[MAXN];
long long dp[MAXN][15];
int main() {
  ios::sync_with_stdio(false);
  long long a, b;
  cin >> n >> m >> a >> b;
  long long a_lv = (a + m - 1) / m, b_lv = (b + m - 1) / m;
  if (a_lv - b_lv == 0 || m == 1) {
    cout << 1 << endl;
  } else if (b_lv - a_lv == 1) {
    if (a % m == 1 && (b % m == 0 || b == n))
      cout << 1 << endl;
    else
      cout << 2 << endl;
  } else {
    if (a % m == 1 && (b % m == 0 || b == n))
      cout << 1 << endl;
    else if (a % m == 1)
      cout << 2 << endl;
    else if (b % m == 0 || b == n)
      cout << 2 << endl;
    else if (a % m - b % m == 1)
      cout << 2 << endl;
    else if (a % m == 0 && b % m == m - 1)
      cout << 2 << endl;
    else
      cout << 3 << endl;
  }
  return 0;
}
