#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int u = 1;
  for (int i = 0; i < n; i++) {
    u *= 10;
  }
  int ans = -1;
  for (int i = u / 10; i < u; i++) {
    bool ok = true;
    string tmp = to_string(i);
    for (int j = 0; j < m; j++) {
      if (tmp[s[j]] != c[j]) {
        ok = false;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans;
}
