#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, b[100], c[100], i, a[100] = {0}, r = 1, j;
  a[1] = 1;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> b[i] >> c[i];
    for (j = 1; j < i; j++) {
      if (b[i] == b[j] && c[i] != c[j]) {
        r = 0;
        break;
      }
    }
    a[b[i]] = c[i];
  }
  if (a[1] == 0 || r == 0) cout << "-1";
  if (n == 1 && m == 0)
    cout << "0";
  else
    for (i = 1; i <= n; i++) {
      cout << a[i];
    }
}
