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