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