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