#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int s[10] = {0};
  cin >> n >> m;
  for (int w, h, i = 0; i < m; i++) {
    cin >> w >> h;
    if (s[w] && s[w] != h) {
      cout << -1 << endl;
      return 0;
    } else
      s[w] = h;
  }
  if (n == 1)
    cout << s[1];
  else {
    if (!s[1])
      cout << -1 << endl;
    else
      cout << s[1] << s[2] << s[3] << endl;
  }
  return 0;
}
