링크 : https://www.acmicpc.net/problem/3135
/*
문제 : 라디오
링크 : https://www.acmicpc.net/problem/3135
*/
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
int A, B;
cin >> A >> B;
int minValue = 1001;
int n;
cin >> n;
vector<int> v;
for(int i = 0; i < n; i++){
int tmp;
cin >> tmp;
minValue = min(minValue, min(abs(A - B), abs(tmp - B) + 1));
}
cout << minValue;
return 0;
}