#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s, c;
  int v[3] = {-1, -1, -1};
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (v[s] == -1 || v[s] == c) {
      v[s] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  if (n == 1) {
    ans = max(v[0], 0);
  }
  if (n == 2) {
    ans = v[0] * 10 + max(v[1], 0);
    if (ans == 0 || ans < 10) ans = -1;
  }
  if (n == 3) {
    ans = v[0] * 100 + max(v[1], 0) * 10 + max(v[2], 0);
    if (ans == 0 || ans < 100) ans = -1;
  }
  cout << ans << endl;
}
