#include <bits/stdc++.h>
using namespace std;
int num[5];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(num, -1, sizeof(num));
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    scanf("%d%d", &s, &c);
    if (num[s] == -1)
      num[s] = c;
    else if (num[s] != c)
      flag = false;
  }
  if (!flag) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (num[i] == -1) num[i] = (i == 1);
    ans += pow(10, n - i) * num[i];
  }
  if (ans == 0 && n > 1) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
