#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long int n, m, ans;
  ans = 0;
  cin >> n >> m;
  long long int num[3];
  num[0] = num[1] = num[2] = 10;
  for (int i = 0; i < m; i++) {
    int tmp, tmp2;
    cin >> tmp >> tmp2;
    tmp = tmp - 1;
    if (num[tmp] == 10) {
      num[tmp] = tmp2;
    } else if (num[tmp] != tmp2) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[0] == 10) num[0] = 1;
  if (num[1] == 10) num[1] = 0;
  if (num[2] == 10) num[2] = 0;
  if (num[0] == 0) {
    cout << -1 << endl;
    return 0;
  } else {
    ans += num[0] * 100 + num[1] * 10 + num[2];
  }
  cout << ans << endl;
}
