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