#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<set<int>> s(n);
  for (long long int i = 0; i < (m); ++i) {
    int t, u;
    cin >> t >> u;
    s[t - 1].insert(u);
  }
  string ans = "";
  for (long long int i = 0; i < (n); ++i) {
    if (s[i].size() == 0) {
      ans = ans + '0';
    } else if (s[i].size() == 1) {
      ans = ans + (to_string(*s[i].begin()));
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (stoi(ans) != 0) {
    cout << stoi(ans) << endl;
  } else {
    for (int i = 0; i < n - 1; i++) {
      if (s[i].size() > 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << stoi(ans) << endl;
  }
  return 0;
}
