#include <bits/stdc++.h>
using namespace std;
int n, m, a[5], s, c;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= 3; i++) a[i] = -1;
  for (int i = 1; i <= m; i++) {
    cin >> s >> c;
    if (n == 1 && c == 0) {
      puts("0");
      return 0;
    }
    if (s == 1 && c == 0) {
      puts("-1");
      return 0;
    } else if (a[s] != -1 && a[s] != c) {
      puts("-1");
      return 0;
    } else
      a[s] = c;
  }
  for (int i = 1; i <= n; i++) cout << (a[i] == -1 ? 0 : a[i]);
  return 0;
}
