#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[6] = {0, 1, 0, -1, 1, -1};
const int vy[6] = {1, 0, -1, 0, 1, 1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, char>> sc(m);
  for (ll i = 0; i < m; ++i) {
    int x;
    char y;
    cin >> x >> y;
    sc[i] = make_pair(x, y);
  }
  ll ans = INF;
  for (int i = 1; i < 1000; ++i) {
    bool f = true;
    string s = to_string(i);
    for (ll j = 0; j < m; ++j) {
      if (s[sc[j].first - 1] != sc[j].second) {
        f = false;
      }
    }
    if (f) {
      ans = i;
      break;
    }
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  cout << endl;
  return 0;
}
