#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const long long inf = 0x3f3f3f3f;
const long long maxn = 201110;
const long long M = 1e9 + 7;
long long n, m, k, ok;
long long a[4];
signed main() {
  cin >> n >> m;
  ok = 1;
  for (long long i = 1, x, y; i <= m; i++) {
    cin >> x >> y;
    if (a[x] != 0 && a[x] != y) ok = 0;
    a[x] = y;
  }
  if (ok) {
    long long i = 3;
    while (a[i] == 0) i--;
    if (i < 1)
      puts("-1");
    else {
      for (long long j = 1; j <= i; j++) {
        cout << a[j];
      }
      cout << endl;
    }
  } else
    puts("-1");
  return 0;
}
