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