#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s, c, ans = -1;
  int v[3] = {-1, -1, -1};
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s--;
    if (v[s] != -1 && v[s] != c) goto fin;
    v[s] = c;
  }
  ans = v[0];
  if (n == 1) {
    if (v[0] == -1) v[0] = 0;
  } else {
    if (v[0] == 0) goto fin;
    if (v[0] == -1) v[0] = 1;
    for (int i = 1; i < n; i++) {
      ans = 10 * ans + ((v[i] == -1) ? 0 : v[i]);
    }
  }
fin:
  cout << ans << endl;
}
