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