#include <bits/stdc++.h>
using namespace std;
int main() {
  int s[10];
  char c[10];
  int M, N;
  int i;
  int cnt = 0;
  cin >> N >> M;
  for (i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  string a(N, '*');
  for (i = 0; i < M; i++) {
    if (a[s[i] - 1] != '*' && a[s[i] - 1] != c[i])
      cnt = -1;
    else
      a[s[i] - 1] = c[i];
  }
  if (a[0] == '*' && N != 1)
    a[0] = '1';
  else if (N == 1)
    a[0] = '0';
  for (i = 0; i < M; i++) {
    if (a[i] == '*') a[i] = '0';
  }
  if (N != 1 && a[0] == '0') cnt = -1;
  if (cnt == -1)
    cout << -1 << endl;
  else
    cout << a << endl;
  return 0;
}
