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