#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n < m) {
    cout << -1 << endl;
    return 0;
  }
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  bool isdecided[n];
  int a[n];
  for (int i = 0; i < m; i++) {
    if (!isdecided[s[i]]) {
      a[s[i]] = c[i];
      isdecided[s[i]] = true;
    } else if (a[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!isdecided[i]) {
      if (i != 0) {
        a[i] = 0;
      } else {
        a[i] = 1;
      }
    }
  }
  if (n > 2 && a[0] == 0) {
    cout << -1 << endl;
    return 0;
  } else {
    int result = 0;
    for (int i = 0; i < n; i++) {
      result *= 10;
      result += a[i];
    }
    cout << result << endl;
  }
}
