#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const long long INF = 1000000000000000000;
int num[10];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < 3; i++) {
    num[i] = mod;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (num[s] == mod) {
      num[s] = c;
    }
    if (num[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < 3; i++) {
    if (i == 0 && num[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (num[i] == mod)
      cout << 0;
    else
      cout << num[i];
  }
  cout << endl;
}
