#include <bits/stdc++.h>
using namespace std;
long long int powk(long long int a, long long int n) {
  long long int r = 1;
  for (long long int i = 0; i < n; i++) {
    r *= a;
  }
  return r;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  vector<pair<long long int, long long int>> sc(m);
  for (long long int i = 0; i < m; i++) {
    cin >> sc[i].first >> sc[i].second;
  }
  sort(sc.begin(), sc.end());
  long long int cnt = 0, tmp = sc[0].second;
  vector<long long int> s(3);
  for (long long int i = 0; i < m; i++) {
    s[sc[i].first - 1] = sc[i].second;
  }
  for (long long int i = 0; i < m; i++) {
    if (s[sc[i].first - 1] != sc[i].second) {
      cout << -1;
      return 0;
    }
  }
  if (s[0] == 0) {
    cout << -1;
    return 0;
  }
  for (long long int i = 0; i < n; i++) {
    cout << s[i];
  }
  return 0;
}
