#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, s, c, i;
  int a[4] = {-20, -1, -1, -1};
  cin >> n >> m;
  string S = "";
  bool ok = 1;
  while (m--) {
    cin >> s >> c;
    if (a[s] == -1)
      a[s] = c;
    else {
      if (a[s] != c) ok = 0;
    }
  }
  if (ok) {
    for (i = 1; i <= 3; ++i)
      if (a[i] != -1)
        S += to_string(a[i]);
      else
        S.append("0");
    int K = stoi(S);
    if ((int)(log10(K)) + 1 == n)
      cout << K << '\n';
    else
      cout << -1 << '\n';
  } else
    cout << -1 << '\n';
}
