#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mp;
long long int ar[673][20];
vector<long long int> vc[1000];
int main() {
  long long int a, b, j, c = 0, m, sum = 0, i, k, l;
  cin >> a >> b;
  for (i = 1; i <= b; i++) {
    cin >> k >> l;
    vc[k].push_back(l);
    if (mp[k] == 0)
      sum++;
    else
      mp[k] = 1;
  }
  if (a == 1 && sum > 0) {
    if (vc[1].size() > 0)
      for (i = 1; i <= a; i++) {
        sort(vc[i].begin(), vc[i].end());
        cout << vc[i][0];
        break;
      }
    else
      cout << "0" << endl;
  } else if (a > 1 && sum >= 2 && vc[1].size() > 0 && vc[1][0] != 0) {
    for (i = 1; i <= a; i++) {
      if (vc[i].size() > 0) {
        sort(vc[i].begin(), vc[i].end());
        cout << vc[i][0];
      } else
        cout << 0;
    }
  } else
    cout << "-1";
}
