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