#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  int f = 0;
  while (m--) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] == -1)
      a[s] = c;
    else if (c == a[s])
      continue;
    else
      f = 1;
  }
  if (f)
    cout << -1;
  else if (n > 1 && a[0] == 0)
    cout << -1;
  else {
    if (a[0] == -1) a[0] = 1;
    for (int i = 1; i < n; i++) {
      if (a[i] == -1) a[i] = 0;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) ans = ans * 10 + a[i];
    cout << ans;
  }
  return 0;
}
