#include <bits/stdc++.h>
using namespace std;
int a[8];
int main() {
  memset(a, -1, sizeof(a));
  int n, m;
  cin >> n >> m;
  int x, y;
  while (m--) {
    cin >> x >> y;
    if (a[x] != -1 && a[x] != y) return cout << "-1", 0;
    a[x] = y;
  }
  if (a[1] == -1) a[1] = 0;
  if (n == 1) return cout << a[1], 0;
  if (a[1] > 0) {
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1) a[i] = 0;
      cout << a[i];
    }
  } else
    cout << "-1";
}
