#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;
int main() {
  int n, m;
  cin >> n >> m;
  int s[10], c[10];
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  int ans = -1;
  int st[] = {0, 0, 10, 100};
  int la[] = {0, 9, 99, 999};
  for (int i = st[n]; i <= la[n]; i++) {
    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (s[j] > n) {
        cout << -1 << endl;
        return 0;
      }
      if (s[j] == 3) {
        if (i % 10 != c[j]) ok = false;
      } else if (s[j] == 2) {
        if ((i % 100) / 10 != c[j]) ok = false;
      } else {
        if (i / 100 != c[j]) ok = false;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
