#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <typename T>
inline void write(T x) {
  long long i = 20;
  char buf[21];
  buf[20] = '\n';
  do {
    buf[--i] = x % 10 + '0';
    x /= 10;
  } while (x);
  do {
    putchar(buf[i]);
  } while (buf[i++] != '\n');
}
void read(long long &x) {
  bool neg = false;
  register long long c;
  x = 0;
  c = getchar();
  if (c == '-') {
    neg = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48;
  if (neg) x *= -1;
}
map<string, long long> mpp;
int main() {
  long long n, a, b, m, ans = 0;
  read(n);
  read(m);
  read(a);
  read(b);
  long long beg = a / m + ((a % m == 0) ? 0 : 1);
  long long end = b / m + (b % m ? 1 : 0);
  long long rem1 = a % m;
  long long rem2 = b % m;
  if (end - beg + 1 >= 3)
    ans = 3;
  else
    ans = end - beg + 1;
  if (m == 1) {
    cout << "1\n";
    return 0;
  }
  if (ans == 1)
    cout << ans << endl;
  else if (ans == 2) {
    if (rem1 == 1) {
      if (rem2 == 0)
        cout << "1\n";
      else if (b == n)
        cout << "1\n";
      else
        cout << ans << endl;
    } else
      cout << ans << endl;
  } else if (ans == 3) {
    if (rem1 == 1 and rem2 == 0) {
      cout << "1\n";
    } else if (((a - 1) % m == b % m)) {
      cout << "2\n";
    } else {
      if (rem1 == 1) {
        ans--;
        if (b == n or rem2 == 0) ans--;
        cout << ans << endl;
      } else if (rem2 == 0) {
        ans--;
        cout << ans << endl;
      } else {
        if (b == n) ans--;
        cout << ans << endl;
      }
    }
  }
  return 0;
}
