#include <bits/stdc++.h>
using namespace std;
using namespace std;
int jousu(int, int);
int jousu(int x00, int y00) {
  int z00 = 1;
  for (int i = 0; i < y00; i++) {
    z00 *= x00;
  }
  return z00;
}
int kurai(int x00, int y00) {
  int z00 = (x00 % jousu(10, y00)) / jousu(10, y00 - 1);
  return z00;
}
int keta(int x00) {
  int z00 = x00;
  int w00 = 0;
  while (z00 != 0) {
    z00 /= 10;
    w00++;
  }
  return w00;
}
int main() {
  int n, m, a;
  int s1;
  string s, b;
  cin >> n >> m;
  vector<int> check(3, 0);
  if (n == 1)
    s = "0";
  else if (n == 2)
    s = "10";
  else if (n == 3)
    s = "100";
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (check[a - 1] == 1 && s[a - 1] != b[0]) {
      cout << "-1" << endl;
      return 0;
    }
    s[a - 1] = b[0];
    check[a - 1] = 1;
  }
  if (s[0] == '0') {
    cout << "-1" << endl;
    return 0;
  }
  cout << s << endl;
}
