#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const long long IINF = 1LL << 62;
const int maxn = 10000005;
int divr[maxn];
void divisor() {
  for (int i = 2; i < sqrt(maxn); i++) {
    if (!divr[i]) {
      for (int j = i * i; j < maxn; j += i)
        if (!divr[j]) divr[j] = i;
    }
  }
  for (int i = 1; i < maxn; i++)
    if (!divr[i]) divr[i] = i;
}
int main() {
  int n, m;
  cin >> n >> m;
  int a[10];
  memset(a, -1, sizeof(a));
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (a[s] != -1 && a[s] != c) {
      cout << -1;
      return 0;
    } else if (a[s] == -1) {
      a[s] = c;
    }
  }
  if (a[1] == 0)
    cout << -1;
  else {
    if (a[1] == -1) a[1] = 1;
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
  }
}
