#include <bits/stdc++.h>
using namespace std;
int leftToRight(int x) {
  if (x == 1) return 2;
  if (x == 2) return 1;
  if (x == 3) return 0;
}
int main() {
  int n, m, s, c;
  cin >> n >> m;
  vector<int> number(4, -1);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    s = leftToRight(s);
    if (number[s] != -1 && number[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
    number[s] = c;
  }
  for (int i = 2; i >= 0; i--) {
    if (number[i] != 0 && number[i] != -1) break;
    if (number[i] == 0) {
      if (i) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  for (int i = 2; i >= 0; i--) {
    if (number[i] != -1) ans += number[i] * pow(10, i);
  }
  cout << ans << endl;
  return 0;
}
