#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s[5] = {0}, c[10] = {0}, x;
  cin >> n >> m;
  int a[n];
  for (int i = 0; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; ++i) {
    for (int j = i + 1; j < m; ++j) {
      if (s[i] == s[j] && c[i] != c[j]) {
        x = -1;
        cout << x;
        return 0;
      }
      if (s[i] == s[j] && c[i] == c[j]) {
        c[i] = -1;
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    if (c[i] >= 0) x += pow(10, n - s[i]) * c[i];
  }
  if (x < pow(10, n - 1) || x >= pow(10, n)) x = -1;
  cout << x;
}
