#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, char>> p(m);
  for (int i = 0; i < (n); i++) cin >> p[i].first >> p[i].second;
  int N, st;
  if (m == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1)
    st = 0, N = 9;
  else if (n == 2)
    st = 10, N = 99;
  else
    st = 100, N = 999;
  for (int i = st; i <= N; i++) {
    bool ok = true;
    string str = to_string(i);
    for (int j = 0; j < (m); j++) {
      if (str[p[j].first - 1] != p[j].second) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << stoi(str) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
