#include <bits/stdc++.h>
using namespace std;
long long MAX = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> m;
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    if (m.find(s) == m.end()) {
      m[s] = c;
    } else {
      if (m[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  vector<int> ans(N, 0);
  for (int i = 0; i < N; ++i) {
    if (i == 0 && m[i + 1] == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans[i] = m[i + 1];
  }
  int res = 0;
  for (int i = 0; i < N; ++i) {
    res = res * 10 + ans[i];
  }
  cout << res << endl;
  return 0;
}
