#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long s[6], c[6];
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (s[i] == 0 && c[i] == 0) {
      cout << -1;
      return 0;
    }
  }
  for (long long j = 0; j <= 999; j++) {
    long long ch[3];
    long long now = j;
    for (long long i = 0; i < 3; i++) {
      ch[2 - i] = now % 10;
      now /= 10;
    }
    bool ans = true;
    for (long long i = 0; i < m; i++) {
      if (ch[s[i]] != c[i]) {
        ans = false;
      }
    }
    if (ans) {
      cout << j;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
