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