#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<pair<int, int>> a(n);
  for (long long i = 0; i < (long long)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1].second > 0) {
      if (a[s - 1].first != c) {
        jdg = false;
      }
    }
    a[s - 1].first = c;
    a[s - 1].second++;
  }
  if (a[0].first == 0) {
    jdg = false;
  }
  if (jdg) {
    for (long long i = 0; i < (long long)(n); i++) {
      cout << a[i].first;
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
