#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int i, j, k;
  int p[m], q[m];
  int a[10];
  for (i = 0; i < 10; i++) a[i] = -1;
  for (i = 0; i < m; i++) {
    cin >> p[i] >> q[i];
  }
  for (i = 0; i < m; i++) {
    if (a[p[i]] == -1) a[p[i]] = q[i];
    if ((a[p[i]] != q[i] && a[p[i]] != -1) || a[1] == 0) {
      cout << "-1";
      return 0;
    }
  }
  for (i = 1; i <= 3; i++) {
    if (a[i] == -1) a[i] = 0;
    if (a[1] == 0) {
      cout << "-1";
      return 0;
    }
    cout << a[i];
  }
}
