#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int num = 1;
  for (int i = 0; i < (int)n - 1; i++) num *= 10;
  vector<int> d(n, 0);
  string cou = to_string(num);
  int f = 0;
  for (int i = 0; i < (int)m; i++) {
    int a;
    char b;
    cin >> a >> b;
    if ((a != n) && b == 0) f = 1;
    if (d[a - 1] == 1 && cou[a - 1] != b) f = 1;
    d[a - 1] = 1;
    cou[a - 1] = b;
  }
  if (f == 1)
    cout << -1 << endl;
  else
    cout << cou << endl;
}
