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