#include <bits/stdc++.h>
using namespace std;
inline long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
inline long long lcm(long long a, long long b) { return a * b / GCD(a, b); }
int main() {
  int n, m;
  cin >> n >> m;
  int s[10], c[10];
  for (long long i = 0; i < (long long)m; i++) {
    cin >> s[i] >> c[i];
  }
  int ans[3];
  memset(ans, 0, sizeof(ans));
  ans[0] = 1;
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
      ans[s[i] - 1] = c[i];
    }
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long i = 0; i < (long long)n; i++) {
    cout << ans[i];
  }
  cout << endl;
}
