#include <bits/stdc++.h>
using namespace std;
const int maxn = 10 + 10;
int main() {
  int n, m, a, b;
  scanf("%d%d%d%d", &n, &m, &a, &b);
  int pos2 = 0, pos3 = 0;
  if (b % m != 0)
    pos2 = b / m + 1;
  else
    pos2 = b / m;
  if (a % m != 0)
    pos3 = a / m + 1;
  else
    pos3 = a / m;
  int cnt = 0;
  if (m == 1 || n <= m || a == b)
    cnt = 1;
  else if (b % m == 0) {
    if (a % m == 1) {
      cnt = 1;
    } else {
      if (pos2 != pos3)
        cnt = 2;
      else
        cnt = 1;
    }
  } else {
    if (a % m == 1) {
      if (b == n)
        cnt = 1;
      else {
        if (pos2 == pos3)
          cnt = 1;
        else
          cnt = 2;
      }
    } else {
      if (b == n)
        cnt = 2;
      else if (pos2 == pos3)
        cnt = 1;
      else if (pos2 - pos3 == 1)
        cnt = 2;
      else {
        if (b % m + 1 == a % m || (b % m + 1 == m && a % m == 0)) {
          cnt = 2;
        } else
          cnt = 3;
      }
    }
  }
  printf("%d\n", cnt);
}
