#include <bits/stdc++.h>
using namespace std;
char p[5];
int main() {
  p[1] = p[2] = p[3] = '*';
  int n, m;
  cin >> n >> m;
  int f = 1;
  while (m--) {
    int a;
    char b;
    cin >> a >> b;
    getchar();
    if (p[a] != '*' && p[a] != b)
      f = 0;
    else
      p[a] = b;
  }
  if (!f)
    return !printf("-1\n");
  else if (p[1] == '0' && n >= 2)
    return !printf("-1\n");
  else {
    if (n == 1 && p[2] == '*' && p[3] == '*')
      if (p[1] != '*')
        cout << p[1] - '0' << "\n";
      else
        cout << 1 << "\n";
    else if (n == 2 && p[3] == '*') {
      if (p[1] == '*') p[1] = '1';
      if (p[2] == '*') p[2] = '0';
      cout << p[1] << p[2] << "\n";
    } else if (n == 3) {
      if (p[1] == '*') p[1] = '1';
      if (p[2] == '*') p[2] = '0';
      if (p[3] == '*') p[3] = '0';
      cout << p[1] << p[2] << p[3] << "\n";
    } else
      cout << "-1\n";
  }
  return 0;
}
