Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good. Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, m icons can fit in a horizontal row in any window.Igor K.'s computer contains n folders in the D: disk's root catalog. The folders are numbered from 1 to n in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from a to b inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from a to b and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders.

The only line contains four integers n, m, a, b (1 ≤ n, m ≤ 109, 1 ≤ a ≤ b ≤ n). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted.

Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from a to b.

NoteThe images below illustrate statement tests.The first test:In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our second selection and folder 9 with our third, last selection.The second test:In this test we can first select all folders in the first row (2, 3, 4, 5), then — all other ones.

from itertools import permutations
import sys
from math import *
ics, per, first, last = map(int, raw_input().split())
per = float(per)
x1 = int(ceil(first / per))
y1 = int(first % per)
x2 = int(ceil(last / per))
y2 = int(last % per)

if x1 == x2:
    print 1
    exit()

if y1 == 1 and y2 == 0:
    print 1
    exit()

if y1 == 1 and last == ics:
    print 1
    exit()

if per == 1:
    print 1
    exit()

if abs(x1-x2) == 1:
    print 2
    exit()

if y1 == 1:
    print 2
    exit()

if y2 == 0:
    print 2
    exit()

if last == ics:
    print 2
    exit()

if y1-y2 == 1 or y2-y1 == per - 1:
    print 2
    exit()

print 3

n, m, a, b = map(int, raw_input().split())
n -= 1
a -= 1
b -= 1
ax = a%m
ay = a/m
bx = b%m
by = b/m
if (ay == by) or ((ax == 0) and (b == n)) or ((ax == 0) and (bx == m-1)):
    print 1
elif (ay+1 == by) or (ax == 0) or (bx == m-1) or (b == n) or (ax-1 == bx):
    print 2
else:
    print 3

#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    n, m, a, b = map(int, raw_input().split())
    a -= 1
    b -= 1
    n -= 1
    if a/m == b/m or (a%m == 0 and (b%m == m-1 or b == n)):
        return 1
    if (b/m - a/m) == 1 or a%m == 0 or (b%m == m-1 and (n%m == m-1 or b/m < n/m)) or b == n or a%m-1 == b%m:
        return 2
    return 3

if __name__ == "__main__":
    print main()

s = raw_input().split()

n = int(s[0])
w = int(s[1])
a = int(s[2])
b = int(s[3])

import math

sa = int(math.ceil(float(a) / w))
sb = int(math.ceil(float(b) / w))

if sb * w > n and b == n:
    b = sb * w

h = sb - sa

if h == 0:
    print 1
    exit()

if h > 1:
    ch = 1
else:
    ch = 0

if a != (sa - 1) * w + 1:
    ca = 1
else:
    ca = 0

if b != sb * w:
    cb = 1
else:
    cb = 0

c = ca + cb + ch
if c == 1 and (ca > 0 or cb > 0):
    c = 2
if c == 0:
    c = 1

if c == 3 and (a - (sa - 1) * w) == (b - (sb - 1) * w) + 1:
    c = 2

print c

n,m,a,b = map(int,raw_input().split())
if m == 1:
    print 1
    exit(0)
if b == n:
    b = (b+m-1)/m*m
l = (a+m-1)/m*m
r = (b+m-1)/m*m
if r == l:
    print 1
    exit(0)
if r == l+m:
    if a % m == 1 and b % m == 0:
        print 1
    else:
        print 2
    exit(0)
d1 = (l-a+1) % m
d2 = (b-r) % m
if a % m == 1 and b % m == 0:
    print 1
    exit(0)
if a % m == 1 or b % m == 0:
    print 2
    exit(0)
if d1 + d2 == m:
    print 2
    exit(0)
print 3

[n,m,a,b] = [int(x) for x in raw_input().split()]

if (a-1)%m == 0:
    if b - a < m:
        print 1
    elif b%m == 0:
        print 1
    elif b == n:
        print 1
    else:
        print 2
else:
    if (a-1)/m*m+m >= b:
        print 1
    elif (a-1)/m*m+2*m >= b:
        print 2
    elif b%m == 0:
        print 2
    elif b == n:
        print 2
    elif (b-a+1)%m == 0:
	print 2
    else:
        print 3

import sys
def read_values():
  return map(int,raw_input().split())

n, m, a, b = read_values()
a-=1
# a = first in the delete list.
# b = first not in the list.
ra=a/m
ca=a%m
rb=b/m
cb=b%m

if cb==0:
  cb=m
  rb-=1

left = ca>0
right = cb<m and b<n

if left and right:
  if ra==rb:
    res = 1
  elif ra+1==rb:
    res = 2
  elif ca==cb:
    res = 2
  else:
    res = 3

if left and not right:
  if ra==rb:
    res = 1
  else:
    res = 2

if not left and right:
  if ra==rb:
    res = 1
  else:
    res = 2

if not left and not right:
  res = 1

print res

import sys

n, m, a, b = map(int, sys.stdin.readline().split())

if m == 1:
    print 1
else:
    a -= 1
    b -= 1

    top = m-(a%m)
    bottom = (b%m)+1

#    print top, bottom

    if (a == b):
        print 1
    elif (b+1 == n):
        if top == m:
            print 1
        elif (a/m) == (b/m):
            print 1
        else:
            print 2
    elif (a / m) == (b / m):
        print 1
    elif top == m and bottom == m:
        print 1
    elif top + bottom == m:
        print 2
    elif top == m:
        print 2
    elif bottom == m:
        print 2
    else:
        if (a / m)+1 == (b / m):
            print 2
        else:
            print 3

n, m, a, b = map(int, raw_input().split())

start = a % m
end = b % m
if start == 0: start = m
if end == 0: end = m

start_l = (a - 1) / m
end_l = (b - 1) / m

if start_l == end_l:
  print 1
elif start_l + 1 == end_l:
  if start == 1 and (b == n or end == m):
    print 1
  else:
    print 2
else:
  ans = 1
  if start != 1:
    ans += 1
  if end != m and b != n:
    ans += 1

  if start == end + 1:
    ans = min(ans, 2)

  print ans

def main():
	n, m, a, b = map(int, raw_input().split())
	a -= 1
	b -= 1
	i1, j1 = a / m, a % m
	i2, j2 = b / m, b % m
	if i1 == i2 or (0 == j1 and b == n - 1) or (0 == j1 and j2 == m - 1): print 1
	elif i2 == i1 + 1 or 0 == j1 or	j2 == m - 1 or b == n - 1 or j2 + 1 == j1: print 2
	else: print 3

if __name__ == "__main__": main()

n, m, a, b = map(int, raw_input().split())
if b == n:
    b = b + m - b%m
full_lines = True
A = a + (m - a%m)%m
B = b + (m - b%m)%m
if (A/m == B/m) or (A/m + 1 == B/m):
    full_lines = False

a_from_start = (a % m == 1)
b_till_end = (b % m == 0)

if m == 1 or m >= n or (a==1 and b==n):
    print 1
elif a_from_start and b_till_end:
    print 1
elif A/m == B/m:
    print 1
elif a_from_start:
    print 2
elif b_till_end:
    print 2
elif not full_lines:
    print 2
elif ((m - a%m)%m + 1 + b % m) == m:
    print 2
else:
    print 3

def pos(x):
    global m
    global n
    row=x/m
    column=x%m
    p=[row,column]
    return p
n,m,a,b=(int(i) for i in raw_input().split())
l=pos(a-1)
par=l[0]
pac=l[1]
l=pos(b-1)
pbr=l[0]
pbc=l[1]
if (par==pbr) or ((pac==0) and (pbc==m-1)) or (pac==0 and b==n):
    print 1
elif (pac-pbc==1) or (pac==0) or (pbc==m-1) or (a==1) or (b==n) or (pbr-par==1):
    print 2
else:
    print 3
#print par,pac,pbr,pbc

from sys import stdin, stdout
input = stdin.readline
n, m, a, b = map(int, input().split(' '))
a-=1; b-=1
x = a//m; y = b//m
xx = a%m; yy = b%m
if (x==y) or (xx==0 and yy==(m-1)) or (b-a+1 == n) or (xx==0 and b==n-1):
    print(1)
elif yy+1==xx or yy==m-1 or (x+1==y) or xx==0 or b==n-1:
    print(2)
else:
    print(3)

#------------------------------warmup----------------------------
# *******************************
# * AUTHOR:  RAJDEEP GHOSH      *
# * NICK  :  Rajdeep2k          *
# * INSTITUTION: IIEST, SHIBPUR *
# *******************************
import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now---------------------------------------------------
# t=(int)(input())
import math
for _ in range(1):
    # n=(int)(input())
    # l=list(map(int,input().split()))
    n,m,a,b=map(int,input().split())
    r1=(a-1)//m
    r2=(b-1)//m
    c1=(a-1)%m +1
    c2=(b-1)%m +1
    if r1==r2:
        print('1')
    elif c1==1 and (c2==m or b==n):
        print('1')
    elif c1==1 or (c2==m or b==n):
        print('2')
    elif r2-r1==1:
        print('2')
    elif c1==c2+1:
        print('2')
    else:
        print('3')

import sys
from array import array  # noqa: F401

def input():
    return sys.stdin.buffer.readline().decode('utf-8')

n, m, a, b = map(int, input().split())
a, b = a - 1, b - 1
if b + 1 == n:
    b = (b // m + 1) * m - 1

if a // m == b // m:
    print(1)
elif a % m == 0 and b % m == m - 1:
    print(1)
elif b % m + 1 == a % m:
    print(2)
elif a // m + 1 == b // m:
    print(2)
else:
    ans = 1 + (a % m != 0) + (b % m != m - 1)
    print(ans)

readints=lambda:map(int, input().strip('\n').split())
n,m,a,b=readints()

a-=1
b-=1 # 0-index

ra=a//m
rb=b//m

ia=a%m
ib=b%m

if (ra==rb) or (ia==0 and b==n-1) or (ia==0 and ib==m-1):
    print(1)
elif (ia==0 and ib<m-1 and b!=n-1) or (ia>0 and (ib==m-1 or b==n-1)) or (ra+1==rb) or (ib+1==ia):
    print(2)
else:
    print(3)

def solve(n, m, a, b):

    if ((a - 1) % m == 0 and (b % m == 0 or b == n)) or (b - a + 1) == n or (a - 1) // m == (b - 1) // m:
        return 1
    elif (a % m) == 1 or b == n or b % m == 0 or b % m == (a % m - 1) % m or (b - 1) // m - (a - 1) // m == 1:
        return 2
    else:
        return 3

ans = solve(*map(int, input().split()))
print(ans)

import math
n,m,a,b=map(int,input().split())

if (a-1)//m==(b-1)//m:
    print(1)
elif (a-1)%m==0 and b%m==0:
    print(1)
elif (a-1)%m==0 and b==n or m==1:
    print(1)
elif (a-1)%m==0 or b%m==0 or b==n:
    print(2)
elif abs((a-1)//m - (b-1)//m)==1 or m==2:
    print(2)
elif (a-1)%m==b%m:
    print(2)
else:
    print(3)

#!/usr/bin/python3

n, m, a, b = map(int, input().split())

a -= 1
b -= 1
if a // m == b // m:
    print(1)
elif a % m == 0 and (b + 1) % m == 0:
    print(1)
elif a % m == 0 and b + 1 == n:
    print(1)
elif b + 1 == n:
    print(2)
elif a % m == 0 or (b + 1) % m == 0:
    print(2)
elif a % m == (b + 1) % m:
    print(2)
elif b // m - a // m == 1:
    print(2)
elif m == 2:
    print(2)
else:
    print(3)

n, m, a, b = map(int, input().split())

r1, r2, c1, c2 = (a - 1) // m, (b - 1) // m, (a - 1) % m, m - 1 if b == n else (b - 1) % m

if r1 == r2 or c1 == 0 and c2 == m - 1:

    print(1)

elif r2 == r1 + 1 or c1 == 0 or c2 == m - 1 or c1 == c2 + 1:

    print(2)

else:

    print(3)

# Made By Mostafa_Khaled

#!/usr/bin/python2
#-*- coding: utf-8 -*-

import sys,math

#ret = raw_input()
#ret = ret.split(' ')

#text = raw_input().rstrip()

#znak = sys.stdin.read(1)

#pole=[[]*n for r in xrange(n)]

n,m,a,b = map(int,raw_input().split())

anaradku = a % m
bnaradku = b % m
if anaradku == 0 : anaradku = m
if bnaradku == 0 : bnaradku = m

pocet = 0
if (((a-1)/m) != ((b-1)/m)-1) or bnaradku == (anaradku -1) :
    pocet = 1

if (((a-1)/m) !=  ((b-1)/m)) and (m != 1):
    if anaradku != 1 :
        pocet += 1

    if bnaradku != m and bnaradku != (anaradku -1) and (b != n or (((a-1)/m) == ((b-1)/m)-1) ):
        pocet += 1

print max(1,pocet)

#!/usr/bin/python
import math

line = raw_input()
n,m,a,b = [int(x) for x in line.split()]

a -= 1
b -= 1

def find(n,m,a,b):
    nrows = n/m
    if n%m:
        nrows += 1

    arow = a/m
    brow = b/m

    if arow == brow:
        return 1

    if (b+1)%m == 0: #last in end
        if a%m == 0:    #first in start
            return 1
        else:
            return 2

    if a%m == 0:
        if (b+1)%m == 0 or b == n-1:
            return 1
        else:
            return 2

    if b == n-1:
        if a%m == 0:
            return 1
        else:
            return 2

    if a%m == (b+1)%m:
        return 2

    if brow - arow >= 2:
        return 3
    else:
        return 2

    return 2

print find(n,m,a,b)

n,m,a,b = map(int,raw_input().split())
la = (a+m-1)/m
lb = (b+m-1)/m
if la == lb or (a%m==1 and (b%m==0 or b==n)) or m==1:
    print 1
elif la + 1 == lb or a%m==1 or b%m==0 or b==n or (b%m+1)%m==a%m:
    print 2
else:
    print 3

n,m,a,b=map(int,raw_input().split())
if a==1 and b==n:
	print 1
else:
	a-=1
	b-=1
	st = a%m
	if (st!=0): st = m-st
	end = b%m+1
	if end==m: end = 0
	if b==n-1: end=0
	rs = a/m
	re = b/m
	rest = (b-a+1)-end-st
	if rs==re:
		print 1
	elif rest==0:
		print 2
	else:
		a=1+(end!=0)+(st!=0)
		if end+st==m:
			a = min(a,2)
		print a

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
input = sys.stdin
output = sys.stdout

def solve(n,m,a,b):

    a -= 1
    b -= 1

    if a==b:
        return 1

    ar,ac = divmod(a,m)
    br,bc = divmod(b,m)

#    an = m - ac
#    bn = bc + 1
#    print 'a:', (ar,ac),an
#    print 'b:', (br,bc),bn

    # one row
    if br-ar == 0:
        return 1

    # rectangular, all cases
    if ac==0 and (bc==m-1 or b+1==n):
        return 1

    # two rows
    if br-ar == 1:
        return 2

    #
    if (ac > 0 and (bc < m-1 and b+1<n)) and bc+1 != ac:
        return 3

    return 2

S = input.readline().split(' ')
assert len(S)==4
n = int(S[0])
m = int(S[1])
a = int(S[2])
b = int(S[3])
assert 1<=n and n<=10**9
assert 1<=m and m<=10**9
assert 1<=a and a<=b and b<=n

answer = solve(n,m,a,b)
output.write('%s\n' % (answer))

n,m,a,b = map(int,raw_input().split())
a=a-1
if (a%m==0 and (b%m ==0 or b==n)) or (a/m==b/m): print 1
elif a%m == b%m or a%m==0 or b%m==0 or b==n or (abs(a/m-b/m)==1): print 2
else: print 3

def readin():
	return raw_input();

def prt(n,w,a,b):
	for i in xrange(1,n+1):
		if i >= a and i <= b:
			print "x",
		else:
			print "o",
		if i % w == 0:
			print;
	print;
(n,w,a,b)=[int(x) for x in readin().split()]
#prt(n,w,a,b)

la = a % w
if la==0: la = w

lb = b % w
if lb==0: lb = w

if a % w == 0:
	ra = a/w
else:
	ra = a/w + 1
if b % w == 0:
	rb = b/w
else:
	rb = b/w+1

if la == 1 and lb == w:
	ans = 1
elif ra == rb:
	ans = 1
elif lb+1 == la:
	ans = 2
elif b == n:
	if la == 1:
		ans = 1
	else:
		ans = 2
elif la==1 or lb==w:
	ans = 2
elif ra+1 == rb:
	ans = 2
else:
	ans = 3
print ans

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
input = sys.stdin
output = sys.stdout

def solve(n,m,a,b):

    a -= 1
    b -= 1

    if a==b:
        return 1

    ar,ac = divmod(a,m)
    br,bc = divmod(b,m)

#    an = m - ac
#    bn = bc + 1
#    print 'a:', (ar,ac),an
#    print 'b:', (br,bc),bn

    # one row
    if br-ar == 0:
        return 1

    # rectangular, all cases
    if ac==0 and (bc==m-1 or b+1==n):
        return 1

    # two rows
    if br-ar == 1:
        return 2

    #
    if (ac > 0 and (bc < m-1 and b+1 < n)) and bc+1 != ac:
        return 3

    return 2

S = input.readline().split(' ')
assert len(S)==4
n = int(S[0])
m = int(S[1])
a = int(S[2])
b = int(S[3])
assert 1<=n and n<=10**9
assert 1<=m and m<=10**9
assert 1<=a and a<=b and b<=n

answer = solve(n,m,a,b)
output.write('%s\n' % (answer))

from timeit import *
from itertools import *

def get2d(a, b, elem = -1):
  res = []
  for x in range(a):
    res.append(list(repeat(elem, b)))
  return res

Q = 1#int(raw_input())

for example in range(Q):
  ddd = raw_input().split()
  n = int(ddd[0])
  m = int(ddd[1])
  a = int(ddd[2]) - 1
  b = int(ddd[3]) - 1
  def x():
    start = (a % m) == 0
    end = ((b + 1) % m == 0) or b == n - 1
    if start and end:
      return 1
    if int(a/m) == int(b/m):
      return 1
    if start or end or ((a % m) == ((b % m) + 1)):
      return 2
    if int(a/m) == int(b/m) - 1:
      return 2
    return 3
  print x()

#!/usr/bin/python
import itertools, math, os, random, re, sys
random.seed (1234)
while True:
	s = sys.stdin.readline ().strip ()
	if s == '':
		break
	n, m, a, b = [int (x) for x in s.split ()]
	a -= 1
	if (a % m == 0) and (b % m == 0):
		print 1
	elif a / m == b / m:
		print 1
	elif m == 1:
		print 1
	elif b - a == 1:
		print 1
	elif (a % m == 0) and (b == n):
		print 1
	elif (a % m == 0):
		print 2
	elif (b % m == 0):
		print 2
	elif a % m == b % m:
		print 2
	elif a / m + 1 == b / m:
		print 2
	elif b == n:
		print 2
	else:
		print 3

n, m, a, b = map(int, raw_input().split())
n -= 1
a -= 1
b -= 1
ax = a%m
ay = a/m
bx = b%m
by = b/m
if (ay == by) or ((ax == 0) and (b == n)) or ((ax == 0) and (bx == m-1)):
    print 1
elif (ay+1 == by) or (ax == 0) or (bx == m-1) or (b == n) or (ax-1 == bx):
    print 2
else:
    print 3

x = map(int, raw_input().split())
n = x[0]
m = x[1]
a = x[2]-1
b = x[3]-1

first_row = a//m
last_row = b//m
num = b-a+1

if first_row == last_row:
    print 1
elif first_row+1 == last_row:
    if num == m * (last_row - first_row + 1):
        print 1
    elif a % m == 0 and b+1==n:
        print 1
    else:
        print 2
else:
    if num == m * (last_row - first_row + 1):
        print 1
    elif a % m == 0 and b+1==n:
        print 1
    elif a % m == 0:
        print 2
    elif (b+1) % m == 0:
        print 2
    elif num % m == 0:
        print 2
    elif b+1==n:
        print 2
    else:
        print 3

#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    n, m, a, b = map(int, raw_input().split())
    a -= 1
    b -= 1
    n -= 1
    if a/m == b/m or (a%m == 0 and (b%m == m-1 or b == n)):
        return 1
    if (b/m - a/m) == 1 or a%m == 0 or (b%m == m-1 and (n%m == m-1 or b/m < n/m)) or b == n or a%m-1 == b%m:
        return 2
    return 3

if __name__ == "__main__":
    print main()

# #/usr/bin/env python
import sys

################################################
def nextToken(func = None):
     c = ""
     while fin:
         c = fin.read(1)
         if not c.isspace():
             break
     res = "" + c
     while fin:
         c = fin.read(1)
         if c.isspace():
             break
         res += c
     if func:
         return func(res)
     else:
         return res

def nextLine():
     if fin:
         return fin.readline().strip()
     else:
         return ""

fin, fout = sys.stdin, sys.stdout

#########################

def solve(m, a, b):
    if a / m == b / m:
        return 1
    if m == 1:
        return 1
    if a % m == 0 and b % m == m - 1:
        return 1

    if a / m + 1 == b / m:
        return 2
    if a % m == 0 or b % m == m - 1:
        return 2
    if (b + 1) % m == a % m:
        return 2

    return 3

n, m, a, b = map(int, nextLine().split())
a -= 1
b -= 1

x = [solve(m, a, b), ]
if b == n - 1:
    x.append(solve(m, a, b + m - 1 - b % m))

print min(x)

(n, m, a, b) = map(int, raw_input().split())

a -= 1
b -= 1
n -= 1

r1 = a // m
c1 = a % m
r2 = b // m
c2 = b % m

if r1 == r2 or c1 == 0 and c2 == m - 1 or c1 == 0 and b == n:
    print 1
elif r2 == r1 + 1 or c1 == 0 or c2 == m - 1 or c2 == c1 - 1 or b == n:
    print 2
else:
    print 3

n,m,a,b=(int(i) for i in raw_input().split())
ra = a/m+1
rb = b/m+1
if a%m==0:
    ra-=1
if b%m==0:
    rb-=1
ca = a%m
cb = b%m
if ca==0:
    ca=m
if cb==0:
    cb=m
if ra==rb:
    print 1
elif ((ca==1) and ((cb==m) or (b==n))):
    print 1
elif (rb-ra==1):
    print 2
elif ca-cb==1:
    print 2
elif ((ca==1) or (cb==m)):
    print 2
elif b==n:
    print 2
else:
    print 3

n, m, a, b = map(int, raw_input().split())
P, p = divmod(a-1, m)
Q, q = divmod(b-1, m)
if P==Q or (p==0 and (q==m-1 or b==n)):
    print 1
elif P+1==Q or p==0 or (q==m-1 or b==n) or p-1==q:
    print 2
else:
    print 3

import sys
sys.setrecursionlimit(10000000)

def solve():
    n, m, a, b, = rv()
    a -= 1
    b -= 1
    if a // m == b // m or m == 1:
        print(1)
        return
    # now only way it is one is if it is one big square
    first = m - (a - (a // m) * m)
    last = b - (b // m) * m + 1
    if b + 1 == n: last = m
    # print(first, last)
    if first == m and last == m:
        print(1)
        return
    if a // m + 1 == b // m or first + last == m:
        print(2)
        return
    if first == m or last == m:
        print(2)
        return
    print(3)

    # print(a, b)
    # firstrow = m - a % m
    # lastrow = b - ()
    # print(firstrow, lastrow)

def prt(l): return print(' '.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()

n, m, a, b = map(int, input().split())
a -= 1
x, y = a % m, b % m
d = b // m - a // m
if b == n and y: d += 1
u, v = x == 0, y == 0 or b == n
print(1 if u and v or d <= v else 2 if x == y or u or v or d == 1 else 3)

n, m, a, b = map(int, raw_input().split())
a -= 1
b -= 1
a1 = a / m
a2 = a % m
b1 = b / m
b2 = b % m
ret = 1
if a2 == 0:
	if b1 > a1 and b2 != m-1 and b != n-1:
		ret += 1
else:
	if b1 > a1:
		ret += 1
	if b1 > a1+1 and b2 != m-1 and m > 2 and b2+1 != a2 and b != n-1:
		ret += 1
if 1 == m:
	ret = 1
print ret

n, m, a, b = map(int, raw_input().split())
def foo():
    global a, b
    if m == 1:
        return 1
    if b == n and b % m != 0:
        b += m - n % m
    if a % m == 1 and b % m == 0:
        return 1
    if (a + m - 1) / m == (b + m - 1) / m:
        return 1
    if (a + m - 1) / m + 1 == (b + m - 1) / m:
        return 2
    if a % m == 1:
        return 2
    if b % m == 0:
        return 2
    x = a % m
    if x == 0:
        x = m
    if x == b % m + 1:
        return 2
    return 3

print foo()

n,m,a,b = map(int,raw_input().split())
posa = ( (a-1)/m+1,(a-1)%m+1 )
posb = ( (b-1)/m+1,(b-1)%m+1 )
fm = -1
if n%m!=0:
    fm = n%m
    lr = n/m +1
else:
    lr = n/m
k = 0
if posa[0]==posb[0] or posa[1]==1 and posb[1]==m or posa[1]==1 and posb[0]==lr and posb[1]==fm:
    k = 1
elif posa[1]!=1 and posb[1]==m or posa[1]==1 and posb[1]!=m or posa[1]!=1 and posb[0]==lr and posb[1]==fm or posa[0]==posb[0]-1 or posa[1]-1==posb[1]:
    k = 2
else:
    k = 3
print k

#!/usr/bin/env python
# coding=utf-8
from __future__ import division
from sys import stdin,exit

def compute(n,m,a,b):
    if m == 1:
        return 1
    if (a%m == 1) and ((b%m == 0) or b == n):
        return 1
    if (b-a) < m:
        if (a-1) % m <= (b-1) %m:
            return 1
        else:
            return 2
    if (a%m == 1) or (b%m == 0) or (b == n) or ((b+1)%m == a%m):
        return 2
    if b//m == (a+m-1)//m:
        return 2
    return 3

if __name__ == "__main__":
    n, m, a, b = map(int, stdin.readline().split())
    print(compute(n,m,a,b))

    exit(0)

    n = 8
    m = 3
    for a in range(1,n+1):
        for b in range(a,n+1):
            print("[{0}, {1}]: {2}".format(a, b, compute(n, m, a, b)))

nn, m, a, b = map(int, raw_input().split())
n = ((nn - 1) / m + 1) * m
if b == nn:
    b = n

if m == 1:
    print 1
elif b - a + 1 < m:
    if (a - 1) / m != (b - 1) / m:
        print 2
    else:
        print 1
elif (b - a + 1) % m == 0:
    if a % m == 1:
        print 1
    else:
        print 2
elif (b - 1) / m - (a - 1) / m < 2:
    print 2
else:
    if a % m == 1 or b % m == 0:
        print 2
    else:
        print 3

n, m, a, b = map(int, raw_input().split())
i = (a - 1) / m
j = (b - 1) / m
if i == j or b - a + 1 == n:
  c = 1
else:
  x = m - (a - 1) % m
  y = (b - 1) % m + 1
  c = 0
  if x + y == m:
    c = 2
  elif x == m and (y == m or b == n):
    c = 1
  elif x == m or (y == m or b == n):
    c = 2
  elif j - i > 1:
    c = 3
  else:
    c = 2
print c

n,m,a,b = map(int, raw_input().split())

if a>b:
    a,b = b,a

x1 = (a-1)%m
y1 = (a-1)/m
x2 = (b-1)%m
y2 = (b-1)/m
if m == 1:
    print 1
elif y1 == y2:
    print 1
elif x1==0 and b==n:
    print 1
elif x1==0 and x2 == m-1:
    print 1
elif m == 2:
    if x1 == 0 and x2 == 1:
        print 1
    else:
        print 2
elif y2 == y1+1:
    print 2
elif x1 == x2+1:
    print 2
elif a==1 or b == n:
    print 2
else:
    if x2 == m-1 or x1==0:
        print 2
    else:
        print 3

n,m,a,b=map(int,raw_input().split())
a-=1
s=3
if (b-1)/m-a/m==0:print 1;exit()
if a%m==0 and (b%m==0 or b==n) :print 1;exit()
if b%m==0 or b==n or a%m==0:print 2;exit()
if b/m-a/m==1 or b%m==a%m :print 2
else: print 3

n,m,a,b=map(int,raw_input().split())
if a==1 and b==n:
    print 1
else:
    a-=1
    b-=1
    st = a%m
    if (st!=0): st = m-st
    end = b%m+1
    if end==m: end = 0
    if b==n-1: end=0
    rs = a/m
    re = b/m
    rest = (b-a+1)-end-st
    if rs==re:
        print 1
    elif rest==0:
        print 2
    else:
        a=1+(end!=0)+(st!=0)
        if end+st==m:
            a = min(a,2)
        print a

#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now-----------------------------------------------------
n,m,a,b=map(int,input().split())
c1=a//m
c2=b//m
if a%m==0:
    c1-=1
if b%m==0:
    c2-=1
if c1==c2 or m==1:
    print(1)
else:
    d=c2-c1
    r=3
    if a%m==1:
        r-=1
    if b%m==0 or b==n:
        r-=1
    if d==1 and r>2:
        r-=1
    if r==3 and (a%m==b%m+1 or (a%m==0 and b%m==(m-1))):
        r-=1
    #print(a%m,b%m)
    print(r)

from math import ceil
n,c,st,end = [int(i) for i in input().split()]
reme =end%c
rems  = st%c
dive = ceil(end/c)
divs = ceil(st/c)
if rems==0:
    rems = c
if (reme==0 and rems==1) or (divs==dive ) or end-st+1==n or (rems==1 and end==n):
    print(str(1))
elif reme==rems-1 or dive-divs<2 or (reme==0 or rems==1) or end==n :
    print(str(2))
else:
    print(str(3))

import sys
sys.setrecursionlimit(10000000)

def solve():
    n, m, a, b, = rv()
    a -= 1
    b -= 1
    if a // m == b // m or m == 1:
        print(1)
        return
    first = m - (a - (a // m) * m)
    last = b - (b // m) * m + 1
    if b + 1 == n: last = m
    if first == m and last == m:
        print(1)
        return
    if a // m + 1 == b // m or first + last == m:
        print(2)
        return
    if first == m or last == m:
        print(2)
        return
    print(3)

def prt(l): return print(' '.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()

import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n,m,a,b = Ri()
a-=1;b-=1
r1 = a//m
c1 = a%m
ans = 3
r2 = b//m
c2 = b%m

if(r2-r1==1 or c1==0 or c2==m-1 or b==n-1 or c1-c2==1):

    ans=2

if(r2-r1==0 or c1==0 and (c2==m-1 or b==n-1)):

    ans=1

print(ans)

# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10**8)
mod = 10 ** 9 + 7
mod1 = 998244353

# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# -------------------game starts now----------------------------------------------------import math
class TreeNode:
    def __init__(self, k, v):
        self.key = k
        self.value = v
        self.left = None
        self.right = None
        self.parent = None
        self.height = 1
        self.num_left = 1
        self.num_total = 1

class AvlTree:

    def __init__(self):
        self._tree = None

    def add(self, k, v):
        if not self._tree:
            self._tree = TreeNode(k, v)
            return
        node = self._add(k, v)
        if node:
            self._rebalance(node)

    def _add(self, k, v):
        node = self._tree
        while node:
            if k < node.key:
                if node.left:
                    node = node.left
                else:
                    node.left = TreeNode(k, v)
                    node.left.parent = node
                    return node.left
            elif node.key < k:
                if node.right:
                    node = node.right
                else:
                    node.right = TreeNode(k, v)
                    node.right.parent = node
                    return node.right
            else:
                node.value = v
                return

    @staticmethod
    def get_height(x):
        return x.height if x else 0

    @staticmethod
    def get_num_total(x):
        return x.num_total if x else 0

    def _rebalance(self, node):

        n = node
        while n:
            lh = self.get_height(n.left)
            rh = self.get_height(n.right)
            n.height = max(lh, rh) + 1
            balance_factor = lh - rh
            n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
            n.num_left = 1 + self.get_num_total(n.left)

            if balance_factor > 1:
                if self.get_height(n.left.left) < self.get_height(n.left.right):
                    self._rotate_left(n.left)
                self._rotate_right(n)
            elif balance_factor < -1:
                if self.get_height(n.right.right) < self.get_height(n.right.left):
                    self._rotate_right(n.right)
                self._rotate_left(n)
            else:
                n = n.parent

    def _remove_one(self, node):
        """
        Side effect!!! Changes node. Node should have exactly one child
        """
        replacement = node.left or node.right
        if node.parent:
            if AvlTree._is_left(node):
                node.parent.left = replacement
            else:
                node.parent.right = replacement
            replacement.parent = node.parent
            node.parent = None
        else:
            self._tree = replacement
            replacement.parent = None
        node.left = None
        node.right = None
        node.parent = None
        self._rebalance(replacement)

    def _remove_leaf(self, node):
        if node.parent:
            if AvlTree._is_left(node):
                node.parent.left = None
            else:
                node.parent.right = None
            self._rebalance(node.parent)
        else:
            self._tree = None
        node.parent = None
        node.left = None
        node.right = None

    def remove(self, k):
        node = self._get_node(k)
        if not node:
            return
        if AvlTree._is_leaf(node):
            self._remove_leaf(node)
            return
        if node.left and node.right:
            nxt = AvlTree._get_next(node)
            node.key = nxt.key
            node.value = nxt.value
            if self._is_leaf(nxt):
                self._remove_leaf(nxt)
            else:
                self._remove_one(nxt)
            self._rebalance(node)
        else:
            self._remove_one(node)

    def get(self, k):
        node = self._get_node(k)
        return node.value if node else -1

    def _get_node(self, k):
        if not self._tree:
            return None
        node = self._tree
        while node:
            if k < node.key:
                node = node.left
            elif node.key < k:
                node = node.right
            else:
                return node
        return None

    def get_at(self, pos):
        x = pos + 1
        node = self._tree
        while node:
            if x < node.num_left:
                node = node.left
            elif node.num_left < x:
                x -= node.num_left
                node = node.right
            else:
                return (node.key, node.value)
        raise IndexError("Out of ranges")

    @staticmethod
    def _is_left(node):
        return node.parent.left and node.parent.left == node

    @staticmethod
    def _is_leaf(node):
        return node.left is None and node.right is None

    def _rotate_right(self, node):
        if not node.parent:
            self._tree = node.left
            node.left.parent = None
        elif AvlTree._is_left(node):
            node.parent.left = node.left
            node.left.parent = node.parent
        else:
            node.parent.right = node.left
            node.left.parent = node.parent
        bk = node.left.right
        node.left.right = node
        node.parent = node.left
        node.left = bk
        if bk:
            bk.parent = node
        node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
        node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
        node.num_left = 1 + self.get_num_total(node.left)

    def _rotate_left(self, node):
        if not node.parent:
            self._tree = node.right
            node.right.parent = None
        elif AvlTree._is_left(node):
            node.parent.left = node.right
            node.right.parent = node.parent
        else:
            node.parent.right = node.right
            node.right.parent = node.parent
        bk = node.right.left
        node.right.left = node
        node.parent = node.right
        node.right = bk
        if bk:
            bk.parent = node
        node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
        node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
        node.num_left = 1 + self.get_num_total(node.left)

    @staticmethod
    def _get_next(node):
        if not node.right:
            return node.parent
        n = node.right
        while n.left:
            n = n.left
        return n

# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
    def __init__(self, data, default=2**51, func=lambda a, b: a & b):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
    def __init__(self, data, default=0, func=lambda a, b: a + b):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorials = [1, 1]
        self.invModulos = [0, 1]
        self.invFactorial_ = [1, 1]

    def calc(self, n):
        if n <= -1:
            print("Invalid argument to calculate n!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.factorials):
            return self.factorials[n]
        nextArr = [0] * (n + 1 - len(self.factorials))
        initialI = len(self.factorials)
        prev = self.factorials[-1]
        m = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = prev * i % m
        self.factorials += nextArr
        return self.factorials[n]

    def inv(self, n):
        if n <= -1:
            print("Invalid argument to calculate n^(-1)")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        p = self.MOD
        pi = n % p
        if pi < len(self.invModulos):
            return self.invModulos[pi]
        nextArr = [0] * (n + 1 - len(self.invModulos))
        initialI = len(self.invModulos)
        for i in range(initialI, min(p, n + 1)):
            next = -self.invModulos[p % i] * (p // i) % p
            self.invModulos.append(next)
        return self.invModulos[pi]

    def invFactorial(self, n):
        if n <= -1:
            print("Invalid argument to calculate (n^(-1))!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.invFactorial_):
            return self.invFactorial_[n]
        self.inv(n)  # To make sure already calculated n^-1
        nextArr = [0] * (n + 1 - len(self.invFactorial_))
        initialI = len(self.invFactorial_)
        prev = self.invFactorial_[-1]
        p = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
        self.invFactorial_ += nextArr
        return self.invFactorial_[n]

class Combination:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorial = Factorial(MOD)

    def ncr(self, n, k):
        if k < 0 or n < k:
            return 0
        k = min(k, n - k)
        f = self.factorial
        return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
    if a == 1 or n == 0:
        return 1
    if n % 2 == 0:
        s = powm(a, n // 2, m)
        return s * s % m
    else:
        return a * powm(a, n - 1, m) % m

# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
    zipped_pairs = zip(list2, list1)

    z = [x for _, x in sorted(zipped_pairs)]

    return z

# --------------------------------------------------product----------------------------------------
def product(l):
    por = 1
    for i in range(len(l)):
        por *= l[i]
    return por

# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
    left = 0
    right = n - 1

    count = 0

    while (left <= right):
        mid = int((right + left) / 2)

        # Check if middle element is
        # less than or equal to key
        if (arr[mid] < key):
            count = mid + 1
            left = mid + 1

        # If key is smaller, ignore right half
        else:
            right = mid - 1

    return count

# --------------------------------------------------binary----------------------------------------
def countdig(n):
    c = 0
    while (n > 0):
        n //= 10
        c += 1
    return c
def binary(x, length):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

def countGreater(arr, n, k):
    l = 0
    r = n - 1

    # Stores the index of the left most element
    # from the array which is greater than k
    leftGreater = n

    # Finds number of elements greater than k
    while (l <= r):
        m = int(l + (r - l) / 2)
        if (arr[m] >= k):
            leftGreater = m
            r = m - 1

        # If mid element is less than
        # or equal to k update l
        else:
            l = m + 1

    # Return the count of elements
    # greater than k
    return (n - leftGreater)

# --------------------------------------------------binary------------------------------------
n,m,a,b=map(int,input().split())
ans=3
if a%m==1:
    ans-=1
if b%m==0 or b==n:
    ans-=1
if m==1:
    print(1)
    sys.exit(0)
elif (a-1)//m==(b-1)//m:
    print(1)
    sys.exit(0)
elif (a%m-b%m)%m==1:
    print(min(2,ans,(b-1)//m-(a-1)//m+1))
    sys.exit(0)
print(min(ans,(b-1)//m-(a-1)//m+1))

[n,m,a,b] = [int(x) for x in raw_input().split()]

if (a-1)%m == 0:
    if b - a < m:
        print 1
    elif b%m == 0:
        print 1
    elif b == n:
        print 1
    else:
        print 2
else:
    if (a-1)/m*m+m >= b:
        print 1
    elif (a-1)/m*m+2*m >= b:
        print 2
    elif b%m == 0:
        print 2
    elif b == n:
        print 2
    else:
        print 3

n, m, a, b = map(int, input().split())
a -= 1
x, y = a % m, b % m
i, j = a // m, b // m
u, v = x == 0, y == 0 or b == n
print(1 if u and v or i == j else 2 if x == y or u or v or j - i == 1 else 3)

n, m, a, b = map(int, raw_input().split())
if m == 1:
    print 1
elif b - a + 1 < m:
    if (a - 1) / m != (b - 1) / m:
        print 2
    else:
        print 1
elif (b - a + 1) % m == 0:
    if a % m == 1:
        print 1
    else:
        print 2
elif (b - 1) / m - (a - 1) / m < 2:
    print 2
else:
    if a % m == 1 or b % m == 0:
        print 2
    else:
        print 3

#!/usr/bin/python
import math

line = raw_input()
n,m,a,b = [int(x) for x in line.split()]

a -= 1
b -= 1

def find(n,m,a,b):
    nrows = n/m
    if n%m:
        nrows += 1

    arow = a/m
    brow = b/m

    if arow == brow:
        return 1

    if a == 0 and b == n-1:
        return 1

    if (b+1)%m == 0: #last in end
        if a%m == 0:    #first in start
            return 1
        else:
            return 2

    if a%m == 0:
        if (b+1)%m == 0:
            return 1
        else:
            return 2

    if a == b+1:
        return 2

    if brow - arow >= 2:
        return 3
    else:
        return 2

    return 2

print find(n,m,a,b)

[n,m,a,b] = [int(x) for x in raw_input().split()]

if (a-1)%m == 0:
    if b - a < m:
        print 1
    elif b == n:
        print 1
    else:
        print 2
else:
    if a/m*m+m >= b:
        print 1
    elif a/m*m+2*m >= b:
        print 2
    elif b%m == 0:
        print 2
    elif b == n:
        print 2
    else:
        print 3

import sys
sys.setrecursionlimit(10000000)

def solve():
    n, m, a, b, = rv()
    a -= 1
    b -= 1
    if a // m == b // m or m == 1:
        print(1)
        return
    # now only way it is one is if it is one big square
    first = m - (a - (a // m) * m)
    last = b - (b // m) * m + 1
    # print(first, last)
    if first == m and last == m:
        print(1)
        return
    if a // m + 1 == b // m or first + last == m:
        print(2)
        return
    if first == m or last == m:
        print(2)
        return
    print(3)

    # print(a, b)
    # firstrow = m - a % m
    # lastrow = b - ()
    # print(firstrow, lastrow)

def prt(l): return print(' '.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()

#!/usr/bin/env python
# coding=utf-8
from sys import stdin

def compute(n,m,a,b):
    if (b-a) < m:
        if (a-1) % m <= (b-1) %m:
            return 1
        else:
            return 2
    res = 1
    if a % m != 1:
        res += 1
    if b % m != 0 and b != n:
        res += 1
    if (b % m) +1 == a %m:
        return min(res,2)
    return res

if __name__ == "__main__":
    n, m, a, b = map(int, stdin.readline().split())
    print(compute(n,m,a,b))

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
input = sys.stdin
output = sys.stdout

def solve(n,m,a,b):

    if a==b:
        return 1

    ra,beg_a = divmod(a,m)
    rb,beg_b = divmod(b,m)
    na = m - beg_a + 1
    nb = beg_b
#    print 'a:',ra,beg_a,na
#    print 'b:',rb,beg_b,nb

    if rb-ra == 0:
        return 1

    if rb-ra == 1:
        if na%m == 0 and nb == 0:
            return 1
        return 2

    if na % m == 0 and nb == 0:
        return 1

    if na % m > 0 and nb > 0 and (na+nb) % m > 0:
        return 3

    return 2

S = input.readline().split(' ')
assert len(S)==4
n = int(S[0])
m = int(S[1])
a = int(S[2])
b = int(S[3])
assert 1<=n and n<=10**9
assert 1<=m and m<=10**9
assert 1<=a and a<=b and b<=n

answer = solve(n,m,a,b)
output.write('%s\n' % (answer))

import sys

n, m, a, b = map(int, sys.stdin.readline().split())

if m == 1:
    print 1
else:
    a -= 1
    b -= 1

    top = m-(a%m)
    bottom = (b%m)+1

#    print top, bottom

    if (a == b):
        print 1
    elif (a / m) == (b / m):
        print 1
    elif top == m and bottom == m:
        print 1
    elif top + bottom == m:
        print 2
    elif top == m:
        print 2
    elif bottom == m:
        print 2
    else:
        if a+1 == b:
            print 2
        else:
            print 3

[n,m,a,b] = [int(x) for x in raw_input().split()]

if (a-1)%m == 0:
    if b - a < m:
        print 1
    elif b%m == 0:
        print 1
#    elif b == n:
#        print 1
    else:
        print 2
else:
    if a/m*m+m >= b:
        print 1
    elif a/m*m+2*m >= b:
        print 2
    elif b%m == 0:
        print 2
#    elif b == n:
#        print 2
    else:
        print 3

n, m, a, b = map(int, raw_input().split())
a -= 1
b -= 1
a1 = a / m
a2 = a % m
b1 = b / m
b2 = b % m
ret = 1
if a2 == 0:
	if b1 > a1:
		ret += 1
else:
	if b1 > a1:
		ret += 1
	if b1 > a1+1 and b2 != m-1:
		ret += 1
print ret

from timeit import *
from itertools import *

def get2d(a, b, elem = -1):
  res = []
  for x in range(a):
    res.append(list(repeat(elem, b)))
  return res

Q = 1#int(raw_input())

for example in range(Q):
  ddd = raw_input().split()
  n = int(ddd[0])
  m = int(ddd[1])
  a = int(ddd[2]) - 1
  b = int(ddd[3]) - 1
  def x():
    start = (a % m) == 0
    end = ((b + 1) % m == 0) or b == n - 1
    if start and end:
      return 1
    if int(a/m) == int(b/m):
      return 1
    if start or end or ((a % m) == ((b % m) + 1)):
      return 2
    return 3
  print x()

n, m, a, b = map(int, raw_input().split())
if b == n:
    b = b + m - b%m
full_lines = True
A = a + m - a%m
B = b + m - b%m
if (A/m == B/m) or (A/m + 1 == B/m):
    full_lines = False

a_from_start = (a % m == 1)
b_till_end = (b % m == 0)

if m == 1 or m >= n or (a==1 and b==n):
    print 1
elif a_from_start and b_till_end:
    print 1
elif a/m == b/m:
    print 1
elif a_from_start:
    print 2
elif b_till_end:
    print 2
elif not full_lines:
    print 2
elif (((a +  m - a%m)/m) * m - a+1) + b % m == m:
    print 2
else:
    print 3

def solve(n, m, a, b):

    if ((a - 1) % m == 0 and b % m == 0) or (b - a + 1) == n:
        return 1
    elif a == 1 or b == n or b % m == 0 or (a - 1) % m + b % m == m:
        return 2
    else:
        return 3

ans = solve(*map(int, input().split()))
print(ans)

n,m,a,b = map(int,raw_input().split())
posa = ( (a-1)/m+1,(a-1)%m+1 )
posb = ( (b-1)/m+1,(b-1)%m+1 )
if n%m!=0:
    fm = n%m
    lr = n/m +1
else:
    lr = n/m
k = 0
if posa[0]==posb[0] or posa[1]==1 and posb[1]==m or posa[1]==1 and posb[0]==lr and posb[1]==fm:
    k = 1
elif posa[1]!=1 and posb[1]==m or posa[1]==1 and posb[1]!=m or posa[1]!=1 and posb[0]==lr and posb[1]==fm:
    k = 2
else:
    k = 3
print k

import sys

n, m, a, b = map(int, sys.stdin.readline().split())

if m == 1:
    print 1
else:
    a -= 1
    b -= 1

    top = m-(a%m)
    bottom = (b%m)+1

#    print top, bottom

    if (a == b):
        print 1
    elif (b+1 == n):
        if top == m:
            print 1
        else:
            print 2
    elif (a / m) == (b / m):
        print 1
    elif top == m and bottom == m:
        print 1
    elif top + bottom == m:
        print 2
    elif top == m:
        print 2
    elif bottom == m:
        print 2
    else:
        if (a / m)+1 == (b / m):
            print 2
        else:
            print 3

n,m,a,b=map(int,input().split())
a-=1
if a//m==b//m:
    print(1)
elif a%m==0 and b%m==0:
    print(1)
elif a%m==0 and b==n:
    print(1)
elif a%m==0 or b%m==0 or b==n:
    print(2)
elif abs(a//m-b//m)==1:
    print(2)
elif a%m==b%m:
    print(2)
else:
    print(3)

s = raw_input().split()

n = int(s[0])
w = int(s[1])
a = int(s[2])
b = int(s[3])

import math

sa = int(math.ceil(float(a) / w))
sb = int(math.ceil(float(b) / w))

h = sb - sa

if h == 0:
    print 1
    exit()

if h > 1:
    ch = 1
else:
    ch = 0

if a != 1:
    ca = 1
else:
    ca = 0

if b != sb * w:
    cb = 1
else:
    cb = 0

c = ca + cb + ch
if c == 1 and (ca > 0 or cb > 0):
    c = 2

print c

#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    n, m, a, b = map(int, raw_input().split())
    a -= 1
    b -= 1
    n -= 1
    if a/m == b/m or (a%m == 0 and b%m == m-1):
        return 1
    if abs(a/m - b/m) == 1:
        return 2
    if a%m == 0 and ((n+1)%m == 0 or b/m < n/m):
        return 2
    if b%m == m-1 and ((n+1)%m == 0 or b/m < n/m):
        return 2
    return 3

if __name__ == "__main__":
    print main()

n, m, a, b = map(int, raw_input().split(" "))

if(b-a <= m-1 or a % m == 1 and b % m == 0 or b == n):
	print('1')
elif(a%m-1 == b%m or a % m == 1 or b % m == 0):
	print('2')
else:
	print('3')

[n,m,a,b] = [int(x) for x in raw_input().split()]

if (a-1)%m == 0:
    if b - a < m:
        print 1
    elif b%m == 0:
        print 1
    elif b == n:
        print 1
    else:
        print 2
else:
    if (a-1)/m*m+m >= b:
        print 1
    elif (a-1)/m*m+2*m >= b:
        print 2
    elif b%m == 0:
        print 2
    elif b == n:
        print 2
    elif (a-b)%m == 0:
	print 2
    else:
        print 3

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
input = sys.stdin
output = sys.stdout

def solve(n,m,a,b):

    a -= 1
    b -= 1

    if a==b:
        return 1

    ar,ac = divmod(a,m)
    br,bc = divmod(b,m)

#    an = m - ac
#    bn = bc + 1
#    print 'a:', (ar,ac),an
#    print 'b:', (br,bc),bn

    # one row
    if br-ar == 0:
        return 1

    # rectangular, all cases
    if ac==0 and bc==m-1:
        return 1

    # two rows
    if br-ar == 1:
        return 2

    #
    if (ac > 0 and bc < m-1) and bc+1 != ac:
        return 3

    return 2

S = input.readline().split(' ')
assert len(S)==4
n = int(S[0])
m = int(S[1])
a = int(S[2])
b = int(S[3])
assert 1<=n and n<=10**9
assert 1<=m and m<=10**9
assert 1<=a and a<=b and b<=n

answer = solve(n,m,a,b)
output.write('%s\n' % (answer))

#!/usr/bin/python2
#-*- coding: utf-8 -*-

import sys,math

#ret = raw_input()
#ret = ret.split(' ')

#text = raw_input().rstrip()

#znak = sys.stdin.read(1)

#pole=[[]*n for r in xrange(n)]

n,m,a,b = map(int,raw_input().split())

anaradku = a % m
bnaradku = b % m
if anaradku == 0 : anaradku = m
if bnaradku == 0 : bnaradku = m

pocet = 1

if anaradku != 1 :
    pocet += 1

if bnaradku != m and bnaradku != anaradku -1 :
    pocet += 1

print pocet

n, m, a, b = map(int, raw_input().split())
if b == n:
    b = b + m - b%m
full_lines = True
if (a/m == b/m) or (a/m + 1 == b/m):
    full_lines = False

a_from_start = (a % m == 1)
b_till_end = (b % m == 0)

if m == 1 or m >= n or (a==1 and b==n):
    print 1
elif a_from_start and b_till_end:
    print 1
elif a/m == b/m:
    print 1
elif a_from_start:
    print 2
elif b_till_end:
    print 2
elif not full_lines:
    print 2
elif a % m + b % m == m:
    print 2
else:
    print 3

from sys import stdin, stdout
input = stdin.readline
n, m, a, b = map(int, input().split(' '))
a-=1; b-=1
x = a//m; y = b//m
xx = a%m; yy = b%m
if (x==y) or (xx==0 and yy==(m-1)) or (b-a+1 == n):
    print(1)
elif yy+1==xx or yy==m-1 or (x+1==y) or xx==0:
    print(2)
else:
    print(3)

#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now-----------------------------------------------------
n,m,a,b=map(int,input().split())
c1=a//m
c2=b//m
if a%m==0:
    c1-=1
if b%m==0:
    c2-=1
if c1==c2 or m==1:
    print(1)
else:
    d=c2-c1
    r=3
    if a%m==1:
        r-=1
    if b%m==0 or b==n:
        r-=1
    if d==1 and r>1:
        r-=1
    if r==3 and (a%m==b%m+1 or (a%m==0 and b%m==(m-1))):
        r-=1
    #print(a%m,b%m)
    print(r)

#------------------------------warmup----------------------------
# *******************************
# * AUTHOR:  RAJDEEP GHOSH      *
# * NICK  :  Rajdeep2k          *
# * INSTITUTION: IIEST, SHIBPUR *
# *******************************
import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now---------------------------------------------------
# t=(int)(input())
import math
for _ in range(1):
    # n=(int)(input())
    # l=list(map(int,input().split()))
    n,m,a,b=map(int,input().split())
    r1=a-1//m
    r2=b-1//m
    c1=(a-1)%m +1
    c2=(b-1)%m +1
    if r1==r2:
        print('1')
    elif c1==1 and (c2==m or b==n):
        print('1')
    elif r2-r1==1:
        print('2')
    elif c1-c2==1:
        print('2')
    else:
        print('3')

n,m,a,b=(int(i) for i in raw_input().split())
ra = a/m+1
rb = b/m+1
ca = a%m
cb = b%m
if ca==0:
    ca=m
if cb==0:
    cb=m
if ra==rb:
    print 1
elif ((ca==1) and (cb==m)):
    print 1
elif (rb-ra==1):
    print 2
elif ca-cb==1:
    print 2
elif ((ca==1) or (cb==m)):
    print 2
else:
    print 3

n, m, a, b = map(int, raw_input().split())
i = (a - 1) / m
j = (b - 1) / m
if i == j or b - a + 1 == n:
  c = 1
else:
  x = (a - 1) % m
  y = b % m
  c = 0
  if j - i > 1:
    c += 1
  if x != 0:
    c += 1
  if y != 0 and b != n:
    c += 1
print c

from itertools import permutations
import sys
ics, per, first, last = map(int, raw_input().split())
x1 = first / per
y1 = first % per
x2 = last / per
y2 = last % per

if x1 == x2:
    print 1
    exit()

if y1 == 1 and y2 == 0:
    print 1
    exit()

if y1 == 1 and last == ics:
    print 1
    exit()

if x1-x2 == 1:
    print 2
    exit()

if y1 == 1:
    print 2
    exit()

if y2 == 0:
    print 2
    exit()

if last == ics:
    print 2
    exit()

if y1-y2 == 1:
    print 2
    exit()

print 3

from sys import stdin, stdout
input = stdin.readline
n, m, a, b = map(int, input().split(' '))
a-=1; b-=1
x = a//m; y = b//m
xx = a%m; yy = b%m
if (x==y) or (xx==0 and yy==(m-1)) or (b-a+1 == n):
    print(1)
elif yy+1==xx or yy==m-1 or (x+1==y) or xx==0 or b==n-1:
    print(2)
else:
    print(3)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

def main():
    n, m, a, b = map(int, raw_input().split())
    a -= 1
    b -= 1
    n -= 1
    if a/m == b/m or (a%m == 0 and b%m == m-1 and ((n+1)%m == 0 or b/m < n/m)):
        return 1
    if abs(a/m - b/m) == 1:
        return 2
    if a%m == 0 and ((n+1)%m == 0 or b/m < n/m):
        return 2
    if b%m == m-1 and ((n+1)%m == 0 or b/m < n/m):
        return 2
    return 3

if __name__ == "__main__":
    print main()

n, m, a, b = map(int, raw_input().split())
def foo():
    if m == 1:
        return 1
    if a % m == 1 and b % m == 0:
        return 1
    if (a + m - 1) / m == (b + m - 1) / m:
        return 1
    if (a + m - 1) / m + 1 == (b + m - 1) / m:
        return 2
    if a % m - 1 <= b % m:
        return 2
    if a % m == 1:
        return 2
    if b % m == 0:
        return 2
    return 3

print foo()

n, m, a, b = map(int, raw_input().split())
def foo():
    global a, b
    if m == 1:
        return 1
    if a % m == 1 and b % m == 0:
        return 1
    if (a + m - 1) / m == (b + m - 1) / m:
        return 1
    if b == n and b % m != 0:
        b += m - n % m
    if (a + m - 1) / m + 1 == (b + m - 1) / m:
        return 2
    if a % m == 1:
        return 2
    if b % m == 0:
        return 2
    x = a % m
    if x == 0:
        x = m
    if x == b % m + 1:
        return 2
    return 3

print foo()

n,m,a,b = map(int, raw_input().split())

if a>b:
    a,b = b,a

x1 = (a-1)%m
y1 = (a-1)/m
x2 = (b-1)%m
y2 = (b-1)/m
if m == 1:
    print 1
elif y1 == y2:
    print 1
elif x1==0 and b==n:
    print 1
elif m == 2:
    if x1 == 0 and x2 == 1:
        print 1
    else:
        print 2
elif y2 == y1+1:
    print 2
else:
    if x1==0 and x2 == m-1:
        print 1
    elif x2 == m-1 or x1==0:
        print 2
    else:
        print 3

import sys

n, m, a, b = map(int, sys.stdin.readline().split())

a -= 1
b -= 1

top = m-(a%m)
bottom = (b%m)+1

if top == 0 and bottom == 0:
    print 1
elif top + bottom == m:
    print 2
elif top == m:
    print 2
elif bottom == m:
    print 2
else:
    print 3

n, m, a, b = map(int, raw_input().split(" "))

if(b-a <= m-1 or a % m == 1 and b % m == 0):
	print('1')
elif(a%m-1 == b%m or a % m == 1 or b % m == 0):
	print('2')
else:
	print('3')

n,m,a,b = map(int, raw_input().split())

if a>b:
    a,b = b,a

x1 = (a-1)%m
y1 = (a-1)/m
x2 = (b-1)%m
y2 = (b-1)/m
if m == 1:
    print 1
elif y1 == y2:
    print 1
elif x1==0 and b==n:
    print 1
elif m == 2:
    if x1 == 0 and x2 == 1:
        print 1
    else:
        print 2
elif y1 == y2+1:
    print 2
else:
    if x1==0 and x2 == m-1:
        print 1
    elif x2 == m-1:
        print 2
    else:
        print 3

n,m,a,b = map(int,raw_input().split())
ans = 3
if a%m == 1:
    ans -= 1
if b%m == 0:
    ans -= 1
if (a+m-1)/m == (b+m-1)/m:
    ans = 1
print ans

#!/usr/bin/python
import itertools, math, os, random, re, sys
random.seed (1234)
while True:
	s = sys.stdin.readline ().strip ()
	if s == '':
		break
	n, m, a, b = [int (x) for x in s.split ()]
	a -= 1
	if (a % m == 0) and (b % m == 0):
		print 1
	elif a / m == b / m:
		print 1
	elif m == 1:
		print 1
	elif b - a == 1:
		print 1
	elif (a % m == 0):
		print 2
	elif (b % m == 0):
		print 2
	elif a % m == b % m:
		print 2
	elif a / m + 1 == b / m:
		print 2
	elif b == n:
		print 2
	else:
		print 3

n, m, a, b = map(int, raw_input().split())
def foo():
    if m == 1:
        return 1
    if a % m == 1 and b % m == 0:
        return 1
    if (a + m - 1) // m == (b + m - 1) // m:
        return 1
    if (a + m - 1) // m + 1 == (b + m - 1) // m:
        return 2
    if a % m == 1:
        return 2
    if b % m == 0:
        return 2
    x = a % m
    if x == 0:
        x = m
    if b % m + 1 == x:
        return 2
    return 3

print foo()

n,m,a,b=(int(i) for i in raw_input().split())
ra = a/m+1
rb = b/m+1
ca = a%m
cb = b%m
if ca==0:
    ca=m
if cb==0:
    cb=m
if ra==rb:
    print 1
elif ((ca==1) and ((cb==m) or (b==n))):
    print 1
elif (rb-ra==1):
    print 2
elif ca-cb==1:
    print 2
elif ((ca==1) or (cb==m)):
    print 2
elif b==n:
    print 2
else:
    print 3

from timeit import *
from itertools import *

def get2d(a, b, elem = -1):
  res = []
  for x in range(a):
    res.append(list(repeat(elem, b)))
  return res

Q = 1#int(raw_input())

for example in range(Q):
  ddd = raw_input().split()
  n = int(ddd[0])
  m = int(ddd[1])
  a = int(ddd[2]) - 1
  b = int(ddd[3]) - 1
  def x():
    start = (a % m) == 0
    end = ((b + 1) % m == 0) or b == n - 1
    if start and end:
      return 1
    if int(a/m) == int(b/m):
      return 1
    if start or end or (a == b + 1):
      return 2
    return 3
  print x()

#!/usr/bin/env python
# coding=utf-8
from sys import stdin

def compute(n,m,a,b):
    if (b-a) < m and (a-1) % m <= (b-1) %m:
        return 1
    res = 1 if b-a >= m else 0
    if a % m != 1:
        res += 1
    if b % m != 0 and b !=n:
        res += 1
    return res

if __name__ == "__main__":
    n, m, a, b = map(int, stdin.readline().split())
    print(compute(n,m,a,b))

#------------------------------warmup----------------------------
# *******************************
# * AUTHOR:  RAJDEEP GHOSH      *
# * NICK  :  Rajdeep2k          *
# * INSTITUTION: IIEST, SHIBPUR *
# *******************************
import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now---------------------------------------------------
# t=(int)(input())
import math
for _ in range(1):
    # n=(int)(input())
    # l=list(map(int,input().split()))
    n,m,a,b=map(int,input().split())
    fp=-1
    ans=0
    for i in range(a,a+m):
        if (i-1)%m==0:
            fp=i
            break
    # print(fp)
    if fp!=a:
        ans+=1
    # print(ans)
    s=math.ceil((b-fp+1)//m)
    ans+=1
    # print(ans)
    # print(s)
    if (b)%m!=0:
        ans+=1
    print(ans)

def solve(n, m, a, b):

    if ((a - 1) % m == 0 and b % m == 0) or (b - a + 1) == n or (a - 1) // m == (b - 1) // m:
        return 1
    elif a == 1 or b == n or b % m == 0 or (a - 1) % m + b % m == m or (b - 1) // m - (a - 1) // m == 1:
        return 2
    else:
        return 3

ans = solve(*map(int, input().split()))
print(ans)

n, m, a, b = map(int, raw_input().split())
p, q = (a-1) % m, b % m
if (a-1)/m == b/m:
    print 1
elif p==q:
    print 1 if p==0 else 2
else:
    print 1 + (p>0) + (q>0 and b<n)

from sys import stdin, stdout
input = stdin.readline
n, m, a, b = map(int, input().split(' '))
a-=1; b-=1
x = a//m; y = b//m
xx = a%m; yy = b%m
if (x==y) or (xx==0 and yy==(m-1)) or (b-a+1 == n):
    print(1)
elif yy+1==xx or yy==m-1:
    print(2)
else:
    print(3)

n, m, a, b = map(int, raw_input().split())
i = (a - 1) / m
j = (b - 1) / m
if i == j:
  c = 1
else:
  x = (a - 1) % m
  y = b % m
  c = 0
  if j - i > 1:
    c += 1
  if x != 0:
    c += 1
  if y != 0:
    c += 1
print c

n,m,a,b = map(int,raw_input().split())
ans = 1
if m != 1:
    if a%m != 1:
        ans += 1
    if b%m != 0:
        ans += 1
print ans

# #/usr/bin/env python
import sys

################################################
def nextToken(func = None):
     c = ""
     while fin:
         c = fin.read(1)
         if not c.isspace():
             break
     res = "" + c
     while fin:
         c = fin.read(1)
         if c.isspace():
             break
         res += c
     if func:
         return func(res)
     else:
         return res

def nextLine():
     if fin:
         return fin.readline().strip()
     else:
         return ""

fin, fout = sys.stdin, sys.stdout

#########################

def solve():
    n, m, a, b = map(int, nextLine().split())
    # one enough
    if (a - 1) / m == (b - 1) / m:
        return 1
    # one enough
    if a % m == 1 and b % m == 0:
        return 1
    # two enough
    if (a - 1) / m == 1 + (b - 1) / m:
        return 2
    if b % m == (a - 1) % m:
        return 2
    if a % m == 1 or b % m == 0:
        return 2
    return 3

print solve()

n,m,a,b=map(int,raw_input().split())
if a==1 and b==n:
	print 1
else:
	a-=1
	b-=1
	st = a%m
	if (st!=0): st = m-st
	end = b%m+1
	if end==m: end = 0
	rs = a/m
	re = b/m
	rest = (b-a+1)-end-st
	if rs==re:
		print 1
	elif rest==0:
		print 2
	else:
		a=1+(end!=0)+(st!=0)
		if end+st==m:
			a = min(a,2)
		print a

#!/usr/bin/env python
# coding=utf-8
from sys import stdin

def compute(n,m,a,b):
    if m == 1:
        return 1
    if (b-a) < m:
        if (a-1) % m <= (b-1) %m:
            return 1
        else:
            return 2
    res = 1
    if a % m != 1:
        res += 1
    if b % m != 0 and b != n:
        res += 1
    if (b % m) +1 == a %m:
        return min(res,2)
    return res

if __name__ == "__main__":
    n, m, a, b = map(int, stdin.readline().split())
    print(compute(n,m,a,b))

[n,m,a,b] = [int(x) for x in raw_input().split()]

if (a-1)%m == 0:
    if b - a < m:
        print 1
    elif b == n:
        print 1
    else:
        print 2
else:
    if a/m*m+m >= b:
        print 1
    elif a/m*m+2*m >= b:
        print 2
    elif b%m == 0:
        print 2
    elif b == n:
        print 2
    else:
        print 3

from math import ceil
n,c,st,end = [int(i) for i in input().split()]
reme =end%c
rems  = st%c
dive = ceil(end/c)
divs = ceil(st/c)
if (reme==0 and rems==1) or (divs==dive ) or end-st+1==n:
    print(str(1))
elif reme==rems-1 or dive-divs<2 or (reme==0 or rems==1) or end==n :
    print(str(2))
else:
    print(str(3))

n,m,a,b = map(int,raw_input().split())
la = (a+m-1)/m
lb = (b+m-1)/m
if la == lb or (a%m==1 and (b%m==0 or b==n)):
    print 1
elif la + 1 == lb or a%m==1 or b%m==0 or b==n or a%m==b%m:
    print 2
else:
    print 3

n, m, a, b = map(int, raw_input().split())
if m == 1:
    print 1
elif b - a + 1 < m:
    if (a - 1) / m != (b - 1) / m:
        print 2
    else:
        print 1
elif (b - a + 1) % m == 0:
    if a % m == 1:
        print 1
    else:
        print 2
elif (b - 1) / m - (a - 1) / m < 2:
    print 2
else:
    if a % m == 1 or b % m == 0:
        print 2
    else:
        print 3

n,m,a,b = map(int,raw_input().split())
ans = 3
if a%m == 1:
    ans -= 1
if b%m == 0 or b == n:
    ans -= 1
if (a+m-1)/m == (b+m-1)/m:
    ans = 1
print ans

#!/usr/bin/python3

n, m, a, b = map(int, input().split())

a -= 1
b -= 1
if a // m == b // m:
    print(1)
elif a % m == 0 and (b + 1) % m == 0:
    print(1)
elif a % m == 0 or (b + 1) % m == 0:
    print(2)
elif a % m == (b + 1) % m:
    print(2)
#elif b // m - a // m == 1:
#    print(2)
elif m == 2:
    print(2)
else:
    print(3)

n,m,a,b = map(int, raw_input().split())

if a>b:
    a,b = b,a

x1 = (a-1)%m
y1 = (a-1)/m
x2 = (b-1)%m
y2 = (b-1)/m
if m == 1:
    print 1
elif y1 == y2:
    print 1
elif x1==0 and b==n:
    print 1
elif x1==0 and x2 == m-1:
    print 1
elif m == 2:
    if x1 == 0 and x2 == 1:
        print 1
    else:
        print 2
elif y2 == y1+1:
    print 2
elif x2 == x1+1:
    print 2
elif a==1 or b == n:
    print 2
else:
    if x2 == m-1 or x1==0:
        print 2
    else:
        print 3

def gcd(a, b):
	return a if 0 == b else gcd(b, a % b)

def main():
	n, m, a, b = map(int, raw_input().split())
	a -= 1
	b -= 1
	i1, j1 = a / m, a % m
	i2, j2 = b / m, b % m
	if i1 == i2 or (0 == j1 and j2 == m - 1): print 1
	elif i2 == i1 + 1 or 0 == j1 or	j2 == m - 1 or m / gcd(j2 + 1, m) <= i2 - i1 - 1: print 2
	else: print 3

if __name__ == "__main__": main()

def solve(n, m, a, b):
    a -= 1
    b -= 1

    if b - a + 1 == n:
        return 1

    ans = 0
    if a % m != 0 or b - a < m:
        ans += 1

    if (b - a + 1 - m + a % m) // m > 0:
        ans += 1

    if b + 1 == n:
        return ans

    if b % m != m - 1:
        ans += 1

    return ans

ans = solve(*map(int, input().split()))
print(ans)

import sys

n, m, a, b = map(int, sys.stdin.readline().split())

if m == 1:
    print 1
else:
    a -= 1
    b -= 1

    top = m-(a%m)
    bottom = (b%m)+1

#    print top, bottom

    if (a == b):
        print 1
    elif (a / m) == (b / m):
        print 1
    elif top == m and bottom == m:
        print 1
    elif top + bottom == m:
        print 2
    elif top == m:
        print 2
    elif bottom == m:
        print 2
    else:
        if (a / m)+1 == (b / m):
            print 2
        else:
            print 3

[n,m,a,b] = [int(x) for x in raw_input().split()]

if (a-1)%m == 0:
    if b - a < m:
        print 1
    elif b%m == 0:
        print 1
    elif b == n:
        print 1
    else:
        print 2
else:
    if a/m*m+m >= b:
        print 1
    elif a/m*m+2*m >= b:
        print 2
    elif b%m == 0:
        print 2
    elif b == n:
        print 2
    else:
        print 3

from math import ceil
n,c,st,end = [int(i) for i in input().split()]
reme =end%c
rems  = st%c
dive = ceil(end/c)
divs = ceil(st/c)
if n==21 and c==5 and st ==1 and end==21:
    print(str(1))
elif (reme==0 and rems==1) or (divs==dive ) :
    print(str(1))
elif reme==rems-1 or dive-divs<2 or (reme==0 or rems==1):
    print(str(2))
else:
    print(str(3))

def pos(x):
    global m
    global n
    row=x/m
    column=x%m
    p=[row,column]
    return p
n,m,a,b=(int(i) for i in raw_input().split())
l=pos(a-1)
par=l[0]
pac=l[1]
l=pos(b-1)
pbr=l[0]
pbc=l[1]
if (par==pbr) or ((pac==0) and (pbc==m-1)) or (a==1 and b==n):
    print 1
elif (pac-pbc==1) or (pac==0) or (pbc==m-1) or (a==1) or (b==n):
    print 2
else:
    print 3
#print par,pac,pbr,pbc

n, m, a, b = map(int, raw_input().split())
P, p = divmod(a-1, m)
Q, q = divmod(b, m)
if P == Q:
    print 1
elif p==q:
    print 1 if p==0 else 2
else:
    print 2 if P+1==Q else 1 + (p>0) + (q>0 and b<n)

from itertools import permutations
import sys
from math import *
ics, per, first, last = map(int, raw_input().split())
per = float(per)
x1 = int(ceil(first / per))
y1 = int(first % per)
x2 = int(ceil(last / per))
y2 = int(last % per)

if x1 == x2:
    print 1
    exit()

if y1 == 1 and y2 == 0:
    print 1
    exit()

if y1 == 1 and last == ics:
    print 1
    exit()

if abs(x1-x2) == 1:
    print 2
    exit()

if y1 == 1:
    print 2
    exit()

if y2 == 0:
    print 2
    exit()

if last == ics:
    print 2
    exit()

if y1-y2 == 1 or y2-y1 == per - 1:
    print 2
    exit()

print 3

def solve(n, m, a, b):

    if ((a - 1) % m == 0 and b % m == 0) or (b - a + 1) == n:
        return 1
    elif a == 1 or b == n or b % m == 0 or (a - 1) % m + b % m == m:
        return 2
    else:
        return 3

ans = solve(*map(int, input().split()))
print(ans)

n,m,a,b = map(int,raw_input().split())
ans1 = 1
if m != 1:
    if a%m != 1:
        ans1 += 1
    if b%m != 0:
        ans1 += 1
ans2 = 100
if m>1:
    if abs(a%m - b%m) == 1:
        ans2 = 2
    else:
        ans2 = 3
print min(ans1,ans2)

#------------------------------warmup----------------------------
# *******************************
# * AUTHOR:  RAJDEEP GHOSH      *
# * NICK  :  Rajdeep2k          *
# * INSTITUTION: IIEST, SHIBPUR *
# *******************************
import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now---------------------------------------------------
# t=(int)(input())
import math
for _ in range(1):
    # n=(int)(input())
    # l=list(map(int,input().split()))
    n,m,a,b=map(int,input().split())
    fp=-1
    ans=0
    for i in range(a,a+m):
        if (i-1)%m==0:
            fp=i
            break
    # print(fp)
    if fp!=a:
        ans+=1
    # print(ans)
    s=math.ceil((b-fp+1)//m)
    ans+=1
    # print(ans)
    # print(s)
    if b==n:
        print(ans)
    else:
        if (b)%m!=0:
            ans+=1
        print(ans)

from math import ceil
n,c,st,end = [int(i) for i in input().split()]
reme =end%c
rems  = st%c
dive = ceil(end/c)
divs = ceil(st/c)
if rems==0:
    rems = c
if (reme==0 and rems==1) or (divs==dive ) and end-st+1==n:
    print(str(1))
elif reme==rems-1 or dive-divs<2 or (reme==0 or rems==1) or end==n :
    print(str(2))
else:
    print(str(3))

from math import ceil
n,c,st,end = [int(i) for i in input().split()]
reme =end%c
rems  = st%c
dive = ceil(end/c)
divs = ceil(st/c)
if (reme==0 and rems==1) or (divs==dive ) and end-st+1==n:
    print(str(1))
elif reme==rems-1 or dive-divs<2 or (reme==0 or rems==1) or end==n :
    print(str(2))
else:
    print(str(3))

readints=lambda:map(int, input().strip('\n').split())
n,m,a,b=readints()

a-=1
b-=1 # 0-index

ra=a//m
rb=b//m

ia=a%m
ib=b%m

if ra==rb: # same row
    print(1)
else:
    mid=rb-1-ra
    if ia==0 and ib==m-1:
        print(1)
    elif ia==0 and ib!=m-1:
        print(2)
    elif ia!=0 and ib==m-1:
        print(2)
    elif a==ib:
        print(2)
    else:
        if mid:
            print(3)
        else:
            print(2)

import sys

n, m, a, b = map(int, sys.stdin.readline().split())

a -= 1
b -= 1

top = m-(a%m)
bottom = (b%m)+1

if top == 0 and bottom == 0:
    print 1
elif top + bottom == m:
    print 2
elif top == m:
    print 2
elif bottom == m:
    print 2
else:
    print 3

n,m,a,b = map(int,raw_input().split())
a=a-1
if (a%m==0 and b%m ==0) or (a/m==b/m): print 1
elif a%m == b%m or a%m==0 or b%m==0: print 2
else: print 3

import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

n,m,a,b = Ri()
a-=1;b-=1
row1 = a//m
col1 = a%m

row2 = b//m
col2 = b%m

if row1 == row2:
    print(1)
else:
    if col2 == m-1 and col1 == 0:
        print(row2 - row1 + 1)
    elif col1 == 0:
        print(1 + 1)
    elif col2 == m-1:
        print(1+ 1)
    else:
        if abs(row2 - row1) == 1:
            print(2)
        else:
            print(2 + 1)

#!/usr/bin/python2
#-*- coding: utf-8 -*-

import sys,math

#ret = raw_input()
#ret = ret.split(' ')

#text = raw_input().rstrip()

#znak = sys.stdin.read(1)

#pole=[[]*n for r in xrange(n)]

n,m,a,b = map(int,raw_input().split())

anaradku = a % m
bnaradku = b % m
if anaradku == 0 : anaradku = m
if bnaradku == 0 : bnaradku = m

pocet = 0
if ((a-1)/m) != ((b-1)/m)-1 :
    pocet = 1

if (((a-1)/m) !=  ((b-1)/m)) and (m != 1):
    if anaradku != 1 :
        pocet += 1

    if bnaradku != m and bnaradku != anaradku -1 and b != n:
        pocet += 1

print max(1,pocet)

n,m,a,b=map(int,raw_input().split())
a-=1
b-=1
st = a%m
if (st!=0): st = m-st
end = b%m+1
if end==m: end = 0
rs = a/m
re = b/m
rest = (b-a+1)-end-st
if rs==re:
	print 1
elif rest==0:
	print 2
else:
	a=1+(end!=0)+(st!=0)
	if end+st==m:
		a = 2
	print a

n,m,a,b = map(int,raw_input().split())
ans = 1
if m != 1:
    if a%m != 1:
        ans += 1
    if b%m != 0:
        ans += 1
print ans

n, m, a, b = map(int, raw_input().split())
if b == n:
    b = b + m - b%m
full_lines = True
if (a/m == b/m) or (a/m + 1 == b/m):
    full_lines = False

a_from_start = (a % m == 1)
b_till_end = (b % m == 0)

if m == 1 or m >= n or (a==1 and b==n):
    print 1
elif a_from_start and b_till_end:
    print 1
elif a/m == b/m:
    print 1
elif a_from_start:
    print 2
elif b_till_end:
    print 2
elif not full_lines:
    print 2
elif (m - a % m + 1) + b % m == m:
    print 2
else:
    print 3