#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  map<int, int> k;
  int f[4];
  memset(f, -1, sizeof(f));
  int dhoro = 0;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (k.count(a)) {
      if (k[a] != b) {
        dhoro = 1;
      }
    }
    k[a] = b;
  }
  if (dhoro)
    cout << "-1" << '\n';
  else {
    for (int i = 1; i <= n; i++) {
      f[i] = k[i];
    }
    if (f[1] == 0) {
      cout << -1 << '\n';
    } else {
      for (int i = 1; i <= n; i++) {
        if (f[i] == -1)
          cout << 0;
        else
          cout << f[i];
      }
      cout << '\n';
    }
  }
}
