#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[10] = {}, c[10] = {};
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    --s[i];
  }
  string ans = "000";
  bool check[4] = {};
  for (int i = 0; i < (m); i++) {
    if (check[s[i]] && ans[s[i]] != '0' + c[i]) {
      cout << (-1) << endl;
      ;
      return 0;
    }
    if (s[i] == 0 && c[i] == 0) {
      cout << (-1) << endl;
      ;
      return 0;
    }
    ans[s[i]] = '0' + c[i];
    check[s[i]] = true;
  }
  cout << (ans) << endl;
  ;
  return 0;
}
