#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& a) {
  a = 0;
  char c;
  bool _MINUS_ = false;
  while (!isdigit(c = getchar())) _MINUS_ |= c == '-';
  do a = a * 10 + (c - '0');
  while (isdigit(c = getchar()));
  if (_MINUS_) a = -a;
}
string world[8] = {"U", "D", "R", "L", "UL", "UR", "DR", "DL"};
const int rx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int ry[8] = {0, 0, 1, -1, -1, 1, 1, -1};
const long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  if (m == 1) {
    cout << 1 << endl;
    return 0;
  }
  int a, b;
  cin >> a >> b;
  if (b == n && b % m != 0) b = b + m - b % m;
  int ans = 3;
  if (a % m == 1) ans = 2;
  if (b % m == 0) ans = 2;
  if ((b - a + 1) % m == 0) ans = 2;
  if ((b - a + 1) <= m) ans = 2;
  if ((b - a + 1) < m + m && ((a % m - 1) + m) % m + m - b % m < m) ans = 2;
  if ((a - 1) / m == (b - 1) / m) ans = 1;
  if (a % m == 1 && b % m == 0) ans = 1;
  cout << ans;
  return 0;
}
