#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  int k[n];
  memset(k, 0, sizeof(k));
  int flag = 1;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (k[s[i] - 1] == 0) {
      k[s[i] - 1] = c[i];
    } else if (k[s[i] - 1] != 0 && k[s[i] - 1] != c[i]) {
      flag = 0;
    }
  }
  if (flag == 0) {
    cout << "-1";
  } else {
    int ans = 0, res = pow(10, n - 1);
    for (int i = 0; i < n; i++) {
      ans = ans * 10 + k[i];
    }
    if (ans >= res) {
      cout << ans << "\n";
    } else {
      cout << "-1";
    }
  }
}
