#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, a, b, c[10] = {0}, i, j, k, l;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    if (c[a - 1] == 0 || c[a - 1] == b)
      c[a - 1] = b;
    else {
      cout << "-1";
      return 0;
    }
  }
  for (i = 0; i < n; i++) cout << c[i];
}
