Problem p02641 (C++) — buggy submission, verdict: Runtime Error

/*  (: ///////|||||| BEGINS |||||||\\\\\\\\ :) */
/* REMEMBER
Deletes all characters except first one     Deletes 4 characters from index
number 1 str.erase(1);                               str.erase(1,4); Deletes
character at position 4 str.erase(str.begin() + 4); bool compare(const pair<int,
int>&a, const pair<int, int>&b)
{
   return a.second<b.second;
}
maxn = max_element(mp.begin(), mp.end(), compare)->second;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second < b.second);
}
min(a,b,c,d)==min({a,b,c,d});
priority_queue <int, vector<int>, greater<int>> gquiz; // to create min heap
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\\n'
#define mod 1000000007
#define fo(i, n) for (int i = 1; i <= n; i++)
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define gcd(a, b) __gcd(a, b)
#define pq priority_queue
#define fr first
#define sc second
#define sz(x) x.size()

const int inf = 0x3f3f3f3f;
bool ispalindrome(string s) {
  ll len = s.length();
  for (ll i = 0; i < len; i++) {
    if (s[i] != s[len - i - 1])
      return false;
  }
  return true;
}
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long isprime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int x, n;
  cin >> x >> n;
  int a[n];
  int h[105] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    h[a[i]] = 1;
  }
  if (n == 0)
    cout << x << endl;
  else {
    vector<pair<int, int>> v;
    for (int i = 0; i <= 102; i++) {
      if (h[i] == 0)
        v.pb({abs(i - x), i});
    }
    sort(all(v));
    cout << v[0].second << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

/*  (: ///////|||||| BEGINS |||||||\\\\\\\\ :) */
/* REMEMBER
Deletes all characters except first one     Deletes 4 characters from index
number 1 str.erase(1);                               str.erase(1,4); Deletes
character at position 4 str.erase(str.begin() + 4); bool compare(const pair<int,
int>&a, const pair<int, int>&b)
{
   return a.second<b.second;
}
maxn = max_element(mp.begin(), mp.end(), compare)->second;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second < b.second);
}
min(a,b,c,d)==min({a,b,c,d});
priority_queue <int, vector<int>, greater<int>> gquiz; // to create min heap
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\\n'
#define mod 1000000007
#define fo(i, n) for (int i = 1; i <= n; i++)
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define gcd(a, b) __gcd(a, b)
#define pq priority_queue
#define fr first
#define sc second
#define sz(x) x.size()

const int inf = 0x3f3f3f3f;
bool ispalindrome(string s) {
  ll len = s.length();
  for (ll i = 0; i < len; i++) {
    if (s[i] != s[len - i - 1])
      return false;
  }
  return true;
}
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long isprime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int x, n;
  cin >> x >> n;
  int a[n];
  int h[105] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    h[a[i]] = 1;
  }
  if (n == 0)
    cout << x << endl;
  else {
    vector<pair<int, int>> v;
    for (int i = 1; i <= 100; i++) {
      if (h[i] == 0)
        v.pb({abs(i - x), i});
    }
    sort(all(v));
    cout << v[0].second << endl;
  }

  return 0;
}