#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  bool jdg = true;
  vector<int> a(n + 1), b(n + 1, 0);
  for (long long i = 0; i < (long long)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (b[s] != 0 && a[s] != c) {
      jdg = false;
    }
    a[s] = c;
    b[s]++;
  }
  if (n >= 2 && a[1] == 0) {
    jdg = false;
  }
  if (jdg == true) {
    for (long long i = 1; i <= (long long)(n); i++) {
      cout << a[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
