#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans = -1;
  cin >> n >> m;
  vector<pair<int, char>> sc;
  for (int i = 0; i < m; ++i) {
    int s;
    char c;
    cin >> s >> c;
    sc.push_back(make_pair(s, c));
  }
  for (int i = pow(10, n - 1) - 1, ma = pow(10, n); i < ma; ++i) {
    bool flag = 1;
    string str = to_string(i);
    for (int j = 0; j < m; ++j) {
      if (str[sc[j].first - 1] != sc[j].second) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans << "\n";
}
