#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n = ({
    int x;
    scanf("%d", &x);
    x;
  }),
            m = ({
              int x;
              scanf("%d", &x);
              x;
            }),
            a = ({
              int x;
              scanf("%d", &x);
              x;
            }),
            b = ({
              int x;
              scanf("%d", &x);
              x;
            }),
            r = 0;
  a--;
  b--;
  int ar = a / m, br = b / m, ac = a % m, bc = b % m;
  if (ar == br)
    r = 1;
  else if (ar + 1 == br) {
    if (ac == 0 && (bc == m - 1 || b == n - 1))
      r = 1;
    else
      r = 2;
  } else {
    if (ac == 0) {
      if (bc == m - 1 || b == n - 1)
        r = 1;
      else
        r = 2;
    } else if (bc == m - 1 || b == n - 1)
      r = 2;
    else {
      r = 3 - ((ac - 1) == bc);
    }
  }
  cout << r << endl;
  return 0;
}
