#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k = 0, e = 0, f = 0;
  cin >> n >> m;
  int c[n];
  memset(c, 0, sizeof(c));
  int a[m], b[m];
  for (i = 0; i < m; i++) cin >> a[i] >> b[i];
  for (i = 0; i < m; i++)
    for (j = i + 1; j < m; j++)
      if (a[i] == a[j] && b[i] != b[j]) {
        cout << -1 << endl;
        return 0;
      }
  for (i = 0; i < m; i++)
    if (a[i] == 1 && b[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  for (i = 0; i < m; i++) {
    if (a[i] == 1) {
      c[a[i] - 1] = b[i];
      k = 1;
    }
    if (a[i] == 2) {
      c[a[i] - 1] = b[i];
      e = 1;
    }
    if (a[i] == 3) {
      c[a[i] - 1] = b[i];
      f = 1;
    }
  }
  if (k == 0) c[0] = 1;
  int ans = 0;
  if (n == 1) cout << c[0];
  if (n == 2) cout << c[0] * 10 + c[1] << endl;
  if (n == 3) cout << c[0] * 100 + c[1] * 10 + c[2] << endl;
  return 0;
}
