#include <bits/stdc++.h>
const int inf = (1 << 30);
const int mod = 1000000007;
using ll = long long;
using namespace std;
int no() {
  cout << -1 << endl;
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  int bound = pow(10, n);
  vector<int> s(m);
  vector<char> c(m);
  vector<int> d(3, -1);
  for (int i = 0; i < m; ++i) {
    int x;
    char y;
    cin >> x >> y;
    if (x < 4 - n) return no();
    --x;
    s[i] = x, c[i] = y;
    if (d[x] == -1)
      d[x] = y;
    else if (d[x] != y)
      return no();
  }
  for (int ans = 0; ans < bound; ++ans) {
    string v = to_string(ans);
    bool flag = true;
    for (int i = 0; i < m; ++i) {
      if (s[i] < (3 - v.size()) or c[i] != v[s[i]]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
