#include <bits/stdc++.h>
using namespace std;
long long gcd(long long, long long);
vector<bool> to_binary(int);
long long nCr(long long n, long long r);
const long long INF = 1LL << 60;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int num[3];
  for (long long i = 0; i < (long long)3; i++) num[i] = -1;
  for (long long i = 0; i < (long long)M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (num[s] != -1 && num[s] != c) {
      cout << -1 << endl;
      goto ProgramEndPointLabel;
    }
    num[s] = c;
  }
  for (long long i = 0; i < (long long)N; i++) {
    if (i == 0 && num[i] <= 0) {
      cout << -1 << endl;
      goto ProgramEndPointLabel;
    }
    if (num[i] == -1)
      cout << 0;
    else
      cout << num[i];
  }
  cout << endl;
ProgramEndPointLabel:;
  system("pause");
  return 0;
}
