#include <bits/stdc++.h>
using namespace std;
int n, m;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  string s(n, '#');
  for (int i = 0; i < m; ++i) {
    int pos;
    char val;
    cin >> pos >> val;
    pos--;
    if (s[pos] != '#') {
      if (s[pos] == val)
        continue;
      else {
        cout << -1;
        return 0;
      }
    }
    s[pos] = val;
  }
  for (int i = 0; i < n; ++i) {
    if (s[i] == '#') s[i] = '0';
  }
  if (s[0] == '0' && n != 1) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i <= 999; ++i) {
    string str = to_string(i);
    if (str == s) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
