#!/bin/bash
read n

n2=0 a2=0
n1=0 a1=0
max=0
while read n0 a0; do
    n=$n0
    (( a1 >= a0 - 2 )) && (( n += n1 ))
    (( a2 >= a0 - 2 )) && (( n += n2 ))
    (( max < n )) && max=$n
    n2=$n1 a2=$a1 n1=$n0 a1=$a0
done < <(xargs -n 1 | sort -n | uniq -c )

echo "${max}"
