#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a, b;
  cin >> n >> m >> a >> b;
  a--;
  b--;
  long long rs = a / m;
  long long re = b / m;
  if (rs == re)
    cout << "1\n";
  else {
    if ((a % m) == 0 && (b % m) == (m - 1))
      cout << "1\n";
    else if ((a % m) == 0 && (b % m) < (m - 1)) {
      if (b == n - 1)
        cout << "1\n";
      else
        cout << "2\n";
    } else if ((a % m) > 0 && (b % m) < (m - 1)) {
      long long aa, bb;
      aa = a % m;
      aa = m - aa;
      bb = b % m;
      bb++;
      if (aa + bb == m)
        cout << "2\n" << endl;
      else {
        if (b == n - 1)
          cout << "2\n";
        else if (b / m - a / m > 1)
          cout << "3\n";
        else
          cout << "2\n";
      }
    } else if ((a % m) > 0 && (b % m) == (m - 1)) {
      cout << "2\n" << endl;
    } else {
    }
  }
  return 0;
}
