#include <bits/stdc++.h>
using namespace std;
int a[100];
signed main() {
  int n, m = 0;
  cin >> n >> m;
  int flag = 0;
  int k = 0, k1 = 0;
  memset(a, -1, sizeof(a));
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &k, &k1);
    if (a[k] == -1) {
      a[k] = k1;
    } else if (a[k] != -1 && a[k] != k1) {
      flag = 1;
    }
  }
  if (a[1] == 0 && n != 1) {
    flag = 1;
  }
  if (flag == 1) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1)
        cout << 0;
      else {
        cout << a[i];
      }
    }
  }
}
