#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  int ans[n];
  int anan = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    ans[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if ((ans[s[i] - 1] == 0 || ans[s[i] - 1] == c[i]) && s[i] != 1) {
      ans[s[i] - 1] = c[i];
    } else if ((ans[s[i] - 1] == 0 || ans[s[i] - 1] == c[i]) && s[i] == 1 &&
               c[i] != 0) {
      ans[s[i] - 1] = c[i];
    } else {
      flag = 1;
      break;
    }
  }
  if (flag == 1 && n == 1) {
    cout << 0 << endl;
  } else if (flag == 1) {
    cout << -1 << endl;
  } else if (ans[0] == 0) {
    ans[0] = 1;
    for (int i = 0; i < n; i++) {
      anan = anan * 10 + ans[i];
    }
    cout << anan << endl;
  } else {
    for (int i = 0; i < n; i++) {
      anan = anan * 10 + ans[i];
    }
    cout << anan << endl;
  }
}
