#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, x, y, sum = 0, lim = 1;
  cin >> n >> m;
  int flag = 1;
  vector<int> a(n, -1);
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    if (a[x - 1] != -1 && a[x - 1] != y) {
      flag = 0;
    }
    a[x - 1] = y;
  }
  if (flag == 0) {
    cout << -1;
  } else {
    for (i = 0; i < n; i++) {
      if (a[i] == -1) {
        a[i] = 0;
      }
      sum = sum * 10 + a[i];
      lim *= 10;
    }
    lim /= 10;
    if (sum < lim) {
      cout << -1;
    } else
      cout << sum;
  }
}
