#include <bits/stdc++.h>
using namespace std;
long long a[4];
int main() {
  long long i, n, t, k, j, x = 0, y = 0, m;
  memset(a, -1, sizeof a);
  cin >> n >> m;
  bool f = 0;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    if (n != 1 && x == 1 && y == 0) f = 1;
    if (a[x] == -1)
      a[x] = y;
    else {
      if (a[x] != y) f = 1;
    }
  }
  if (f) {
    cout << -1 << "\n";
    return 0;
  }
  if (n == 1) {
    if (a[1] == -1)
      cout << 0 << "\n";
    else
      cout << a[1] << "\n";
  } else {
    for (i = 1; i <= m; i++) {
      if (a[i] == -1) {
        if (i == 1)
          cout << 1;
        else
          cout << 0;
      } else
        cout << a[i];
    }
    cout << "\n";
  }
  return 0;
}
