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