#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, char>> vec;
  for (int i = 0; i < m; i++) {
    int s;
    char c;
    cin >> s >> c;
    vec.push_back(make_pair(s, c));
  }
  for (auto x : vec) {
    bool ng = false;
    int a = x.first;
    char b = x.second;
    for (auto y : vec) {
      int c = y.first;
      char d = y.second;
      if ((a == c && b != d) || (n > 1 && a == 1 && b == '0')) ng = true;
    }
    if (ng) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<char> ans(n, '0');
  for (auto x : vec) {
    int a = x.first;
    char b = x.second;
    a--;
    ans[a] = b;
  }
  string res;
  for (int i = 0; i < n; i++) res += ans[i];
  cout << res << endl;
  return 0;
}
