#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int i, j, f = 1;
  long long int ar1[110] = {0};
  long long int ar2[110] = {0};
  long long int mx = 0;
  long long int f1 = 90;
  long long int f2 = 90;
  long long int f3 = 90;
  long long int a, b;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    mx = max(a, mx);
    if (a == 1) f1 = min(b, f1);
    if (a == 2) f2 = min(b, f2);
    if (a == 3) f3 = min(b, f3);
    if (a == 1 && b == 0) f = 0;
    ar1[a]++;
    ar2[b]++;
    if (ar1[a] != ar2[b]) f = 0;
  }
  if (f1 == 90) f1 = 1;
  if (f2 == 90) f2 = 0;
  if (f3 == 90) f3 = 0;
  if (mx > n || f == 0)
    cout << -1 << endl;
  else {
    if (n == 1)
      cout << f1 << endl;
    else if (n == 2)
      cout << f1 << f2 << endl;
    else if (n == 3)
      cout << f1 << f2 << f3 << endl;
  }
  return 0;
}
