#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M];
  int c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int ans[N];
  for (int i = 0; i < N; i++) {
    ans[i] = 10;
  }
  int err = 0;
  for (int i = 0; i < M; i++) {
    if (ans[s[i] - 1] != 10) {
      if (ans[s[i] - 1] != c[i]) err = 1;
    }
    ans[s[i] - 1] = c[i];
  }
  if (ans[0] == 0) err = 1;
  if (err == 1) cout << "-1" << endl;
  if (err == 0) {
    for (int i = 0; i < N; i++) {
      if (ans[i] == 10) ans[i] = 0;
      cout << ans[i];
    }
  }
  cout << endl;
}
