#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[10] = {"0000"};
int s[15], c[15];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
  }
  bool isbad = 0;
  bool flag = 0;
  for (int i = 1; i <= m; i++) {
    if (s[i] > n) {
      isbad = 1;
      break;
    }
    char ch = c[i] + '0';
    if (str[s[i]] == '0') {
      flag = 1;
      str[s[i]] = ch;
    } else {
      if (str[s[i]] != ch) {
        isbad = 1;
        break;
      }
    }
  }
  if (!flag) isbad = 1;
  if (str[3 - n + 1] == '0') isbad = 1;
  if (isbad)
    cout << -1;
  else
    cout << str + 1;
  return 0;
}
