#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
  if (b > a) a = b;
}
int cond = (long long)1;
void _main() {
  int n, m, a, b;
  scanf("%d%d", &n, &m);
  scanf("%d%d", &a, &b);
  a--;
  b--;
  int r1 = a / m;
  int c1 = a % m;
  int r2 = b / m;
  int c2 = b % m;
  {
    if (cond > 0) {
      cond--;
      for (int xxx = (0); xxx < (1); ++xxx)
        cerr << 59 << " "
             << "r1 << \" \" << c1"
             << " " << r1 << " " << c1 << endl;
      cerr.flush();
    }
  };
  {
    if (cond > 0) {
      cond--;
      for (int xxx = (0); xxx < (1); ++xxx)
        cerr << 60 << " "
             << "r2 << \" \" << c2"
             << " " << r2 << " " << c2 << endl;
      cerr.flush();
    }
  };
  if (r1 == r2)
    cout << 1 << endl;
  else {
    if (r1 == r2 - 1) {
      cout << ((c1 != 0 || (c2 != m - 1 && b + 1 != n)) ? 2 : 1) << endl;
    } else {
      int cost = 1;
      cost += c1 != 0;
      cost += (c2 != m - 1) && b + 1 != n;
      if (c2 + 1 == c1) cost = min(cost, 2);
      cout << cost << endl;
    }
  }
}
int main(int argc, char **argv) {
  string p = "../gcj/source/" + string("") + argv[0][strlen(argv[0]) - 1];
  for (int i = (0); i < (argc); ++i)
    if (strcmp(argv[i], "1n") == 0) {
      freopen("1.in", "r", stdin);
    }
  for (int i = (0); i < (argc); ++i)
    if (strcmp(argv[i], "2n") == 0) {
      freopen("2.in", "r", stdin);
    }
  for (int i = (0); i < (argc); ++i)
    if (strcmp(argv[i], "3n") == 0) {
      freopen("3.in", "r", stdin);
    }
  for (int i = (0); i < (argc); ++i)
    if (strcmp(argv[i], "4n") == 0) {
      freopen("4.in", "r", stdin);
    }
  for (int i = (0); i < (argc); ++i)
    if (strcmp(argv[i], "5n") == 0) {
      freopen("5.in", "r", stdin);
    }
  for (int i = (0); i < (argc); ++i)
    if (strcmp(argv[i], "s0") == 0) {
      freopen((p + "-small-0.in").c_str(), "r", stdin);
      freopen((p + "-small-0.out").c_str(), "w", stdout);
    }
  for (int i = (0); i < (argc); ++i)
    if (strcmp(argv[i], "s1") == 0) {
      freopen((p + "-small-1.in").c_str(), "r", stdin);
      freopen((p + "-small-1.out").c_str(), "w", stdout);
    }
  for (int i = (0); i < (argc); ++i)
    if (strcmp(argv[i], "s2") == 0) {
      freopen((p + "-small-2.in").c_str(), "r", stdin);
      freopen((p + "-small-2.out").c_str(), "w", stdout);
    }
  for (int i = (0); i < (argc); ++i)
    if (strcmp(argv[i], "l0") == 0) {
      freopen((p + "-large-0.in").c_str(), "r", stdin);
      freopen((p + "-large-0.out").c_str(), "w", stdout);
    }
  for (int i = (0); i < (argc); ++i)
    if (strcmp(argv[i], "q") == 0) cond = 1 << 30;
  _main();
  return 0;
}
