#include <bits/stdc++.h>
using namespace std;
string tostring(int n) {
  string s1;
  while (n != 0) {
    s1 += (char)(n % 10 + 48);
    n /= 10;
  }
  return s1;
}
int n, m, temp, x;
bool b;
int main() {
  cin >> n >> m;
  int s[m], c[m], temp = 1;
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 1; i < n; ++i) {
    temp *= 10;
  }
  for (int i = temp; i < temp * 10; ++i) {
    b = true;
    string s = tostring(i);
    for (int j = 0; j < m; ++j)
      if (s[s[j]] != c[j]) {
        b = false;
        break;
      }
    if (b) {
      cout << b;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
