#include <bits/stdc++.h>
using std::abs;
using std::cin;
using std::cout;
using std::endl;
using std::max;
using std::min;
using std::string;
using std::vector;
const int MOD = 1000000007;
const long long int INF = 5000000000000;
struct edge {
  int to;
  double cost;
};
long long int N, M;
long long int A[100010], B[100010];
long long int K[11], P[11];
long long int ans;
char S[100];
int main() {
  cin >> N >> M;
  for (int i = 0; i < signed(20); i++) S[i] = 'a';
  {} {}
  for (int i = 0; i < signed(M); i++) {
    char s, t;
    int a, b;
    cin >> a >> b;
    s = a + '0', t = b + '0';
    {} {}
    if (S[a - 1] == 'a')
      S[a - 1] = t;
    else if (S[a - 1] != t) {
      cout << "-1";
      return 0;
    }
  }
  if (S[0] == 'a') S[0] = '1';
  if (S[0] == '0') {
    cout << "-1";
    return 0;
  }
  for (int i = 0; i < signed(N); i++) {
    if (S[i] == 'a')
      cout << '0';
    else
      cout << S[i];
  }
  return 0;
}
