#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a, b, c[10], i, j, k, l, p = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) c[i] = -1;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    if (c[a - 1] == -1 || c[a - 1] == b)
      c[a - 1] = b;
    else
      p++;
  }
  if (p == 0) {
    if (c[0] == 0) {
      if (n > 1) cout << "-1";
      if (n == 1) cout << c[0];
    } else {
      if (c[0] == -1 && n > 1) cout << "1";
      if (c[0] == -1 && n == 1) cout << "0";
      for (i = 1; i < n; i++) {
        if (c[i] == -1)
          cout << "0";
        else
          cout << c[i];
      }
    }
  } else
    cout << "-1";
}
