#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string ans;
  for (int i = 0; i < n; i++) {
    ans.push_back('x');
  }
  for (int i = 0; i < m; i++) {
    int s;
    char c;
    cin >> s >> c;
    if (ans[s - 1] == 'x') {
      ans[s - 1] = c;
    } else {
      if (c != ans[s - 1]) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  if (ans[0] == '0') {
    cout << "-1" << endl;
    return 0;
  }
  if (n == 1 && ans[0] == 'x') {
    ans[0] = '1';
  }
  if (n != 1 && ans[1] == 'x') {
    ans[1] = '0';
  }
  if (n == 3 && ans[2] == 'x') {
    ans[2] = '0';
  }
  cout << ans << endl;
  return 0;
}
