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