#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N, -1);
  int s, c;
  int ans = 0;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (a[s - 1] == -1) {
      a[s - 1] = c;
    } else {
      if (a[s - 1] != c) {
        ans = -1;
      }
    }
  }
  if (ans == -1) {
    cout << ans << endl;
  } else {
    if (a[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (auto p : a) {
      ans *= 10;
      if (p != -1) {
        ans += p;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
