#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int solve1() {
  int n, m, ans;
  int number[3];
  bool exist = true;
  cin >> n >> m;
  for (ll i = 0; i < m; i += 1) {
    int s, c;
    cin >> s >> c;
    --s;
    if (number[s] == 0 || (number[s] != 0 && number[s] == c)) {
      number[s] = c;
    } else {
      exist = false;
    }
  }
  if (exist) {
    ans = number[0] * 100 + number[1] * 10 + number[2];
    if ((int)to_string(ans).length() != n) {
      ans = -1;
    }
  } else {
    ans = -1;
  }
  return ans;
}
int main(void) {
  cout << solve1() << endl;
  return 0;
}
