#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;
  }
  int ans;
  if (!f) return !printf("-1\n");
  if (p[2] == p[3] && p[2] == '*')
    ans = (p[1] - '0');
  else if (p[3] == '*')
    ans = (p[1] - '0') * 10 + (p[2] - '0');
  else {
    if (p[1] == '*')
      p[1] = '0';
    else if (p[2] == '*')
      p[2] = '0';
    ans = (p[1] - '0') * 100 + (p[2] - '0') * 10 + (p[3] - '0');
  }
  int temp = ans;
  int sum = 0;
  while (temp > 0) {
    temp /= 10;
    sum++;
  }
  if (ans == 0 && n == 1) return !printf("0\n");
  if (sum > n)
    return !printf("-1\n");
  else {
    int pp = n - sum;
    while (pp--) {
      ans *= 10;
    }
    printf("%d\n", ans);
  }
  return 0;
}
