#include <bits/stdc++.h>
using namespace std;
int a[10];
int main() {
  int n, m;
  cin >> n >> m;
  int s, t;
  int f = 1;
  memset(a, -1, sizeof(a));
  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    if (a[s] == -1 || a[s] == t)
      a[s] = t;
    else
      f = 0;
  }
  if (f) {
    if (a[1] != 0 || (a[1] == 0 && n == 1)) {
      for (int i = 1; i <= n; i++) {
        if (a[i] == -1)
          cout << '0';
        else
          cout << a[i];
      }
      cout << endl;
    } else {
      cout << "-1" << endl;
    }
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
