#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000000;
int main() {
  int n, m;
  cin >> n >> m;
  int roop = 10;
  for (int i = 0; i < n - 1; ++i) {
    roop *= 10;
  }
  vector<int> s(m), c(m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    x--;
    s[i] = x;
    c[i] = y;
  }
  for (int i = 0; i < roop; ++i) {
    string S = to_string(i);
    bool isans = true;
    for (int i = 0; i < m; ++i) {
      if (S[s[i]] != c[i] + '0') {
        isans = false;
      }
    }
    if (isans) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
