#include <bits/stdc++.h>
using namespace std;
int num[10];
int main() {
  bool flag = true;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) num[i] = -1;
  for (int i = 1; i <= m; ++i) {
    int temp, val;
    cin >> temp >> val;
    if (num[temp] != -1 && num[temp] != val) flag = false;
    num[temp] = val;
  }
  if (flag == false) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i == 1) {
      if (num[1] == -1)
        ans = 1;
      else
        ans = num[1];
    } else {
      ans *= 10;
      if (num[i] == -1)
        continue;
      else
        ans += num[i];
    }
  }
  int temp = ans, cnt = 0;
  while (temp) {
    temp /= 10;
    cnt++;
  }
  if (cnt != n)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
