#include <bits/stdc++.h>
using namespace std;
long long sdkys(long long a, long long b) {
  if (b == 0) return a;
  return sdkys(b, a % b);
}
long long sskbs(long long a, long long b) { return a * b / sdkys(a, b); }
long long sosu(long long a) {
  if (a == 2) {
    return 1;
  }
  for (long long i = 2; i < sqrt(a) + 1; i++) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
vector<long long> aa, ab;
long long n, m, cnt = 0, ans = 0;
pair<long long, char> pp[220000];
string s, sa[220000];
char ch;
queue<long long> que;
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> pp[i].first >> pp[i].second;
  }
  for (long long i = 0; i < 1000; i++) {
    s = to_string(i / 100) + to_string(i / 10 % 10) + to_string(i % 10);
    for (long long j = 0; j < m; j++) {
      if (s[pp[j].first - 1] != pp[j].second) {
        goto no;
      }
    }
    if (i >= pow(10, n - 1)) {
      cout << i << endl;
      return 0;
    } else if (i == 0 && n == 1) {
      cout << 0 << endl;
      return 0;
    }
  no:;
  }
  cout << -1 << endl;
}
