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