#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, k, y, zm;
  char a, b;
  cin >> n >> m;
  vector<pair<char, char> > v;
  stringstream ss;
  string s = "1";
  for (int i = 0; i < n - 1; i++) {
    s += '0';
  }
  cout << s << endl;
  ss << s;
  while (ss >> x) {
    k = x;
    break;
  }
  while (m--) {
    cin >> a >> b;
    v.push_back({a, b});
  }
  int c = 0;
  for (int i = 1; i < 999; i++) {
    int c = 0;
    ostringstream str1;
    str1 << i;
    string sx = str1.str();
    for (int j = 0; j < v.size(); j++) {
      if (sx[v[j].first - 1] != v[j].second) {
        c = 1;
      }
    }
    if (c == 0) {
      cout << sx << endl;
      return 0;
    }
  }
  cout << "-1\n";
}
