#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int INF = 1 << 30;
long long INFL = 1LL << 60;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (long long i = 0; i < (M); i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> num(M + 1, -1);
  bool hantei = false;
  for (long long i = 0; i < (M); i++) {
    if (num[s[i]] == -1)
      num[s[i]] = c[i];
    else if (num[s[i]] == c[i])
      num[s[i]] = c[i];
    else
      hantei = true;
  }
  if (num[1] < 0) num[1] = 1;
  if (hantei || num[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    if (num[i] != -1)
      cout << num[i];
    else
      cout << 0;
  }
  cout << endl;
}
