#include <bits/stdc++.h>
int main() {
  int n, m, a, b;
  scanf("%d %d %d %d", &n, &m, &a, &b);
  int start_row = a / m;
  if (a % m == 0) start_row--;
  start_row++;
  int start_col = a % m;
  if (a % m == 0) start_col = m;
  int end_row = b / m;
  if (b % m == 0) end_row--;
  end_row++;
  int end_col = b % m;
  if (b % m == 0) end_col = m;
  if (start_row == end_row) {
    puts("1");
    return 0;
  }
  if (b == n) {
    if (start_col == 1) {
      puts("1");
      return 0;
    }
    puts("2");
    return 0;
  }
  if (start_col == 1) {
    if (end_col == m) {
      puts("1");
      return 0;
    } else {
      puts("2");
      return 0;
    }
  }
  if (start_col == m) {
    if (end_col == m) {
      puts("2");
      return 0;
    }
    if (end_col == m - 1) {
      puts("2");
      return 0;
    }
    if (start_row + 1 == end_row) {
      puts("2");
      return 0;
    }
    puts("3");
    return 0;
  }
  if (start_col == end_col) {
    if (start_row + 1 == end_row) {
      puts("2");
      return 0;
    }
    puts("3");
    return 0;
  }
  if (start_col > end_col) {
    if (end_col + 1 == start_col) {
      puts("2");
      return 0;
    }
    if (start_row + 1 == end_row) {
      puts("2");
      return 0;
    }
    puts("3");
    return 0;
  }
  if (start_col < end_col) {
    if (start_row + 1 == end_row) {
      puts("2");
      return 0;
    }
    if (end_col == m) {
      puts("2");
      return 0;
    }
    puts("3");
    return 0;
  }
  return 0;
}
