#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
int a[10];
int main() {
  memset(a, 0, sizeof(a));
  int n, m;
  scanf("%d %d", &n, &m);
  int fl = 0;
  while (m--) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (a[x] == 0 || a[x] == y)
      a[x] = y;
    else
      fl = 1;
    if (x == 1 && y == 0 && n != 1) fl = 1;
  }
  if (fl)
    cout << -1 << endl;
  else {
    for (int i = 1; i <= n; i++) printf("%d", a[i]);
    cout << endl;
  }
  return 0;
}
