#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  a--;
  b--;
  int r = 0;
  if (m == 1)
    r = 1;
  else {
    int a2 = a;
    if (a % m) {
      r++;
      a2 = (a / m) * m + m;
    }
    if (a2 <= b) {
      if (b % m == a % m - 1)
        r++;
      else {
        a = a2;
        r++;
        a += m;
        if (a <= b) {
          if ((b + 1) % m != 0 && b != n - 1) r++;
        }
      }
    }
  }
  cout << r << endl;
  return 0;
}
