#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  char s[m], c[m];
  char ch[n + 1];
  for (int i = 1; i <= n; i++) ch[i] = '*';
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    if (s[i] == '1' && c[i] == '0') {
      cout << -1 << endl;
      return 0;
    }
    if (ch[s[i] - 48] != '*' && ch[s[i] - 48] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    ch[s[i] - 48] = c[i];
  }
  for (int i = 1; i <= n; i++) {
    if (ch[i] == '*') ch[i] = '0';
    cout << ch[i];
  }
  cout << endl;
  return 0;
}
