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