#include <bits/stdc++.h>
using namespace std;
priority_queue<long long int> pq;
long long int ara[1000006];
long long int p[100005];
map<long long int, long long int> vis;
int main() {
  long long int n, m, c = 0, str = -1;
  scanf("%lld%lld", &n, &m);
  for (long long int i = 1; i <= m; i++) {
    long long int a, b;
    scanf("%lld%lld", &a, &b);
    if (vis[a] != 0 && vis[a] != b) {
      c++;
    }
    if (c == 0) {
      vis[a] = b;
      if (a == 1 && b == 0) str = b;
    }
  }
  if (c == 0) {
    if (vis[1] == 0 && n != 1 && str == 0) {
      cout << "-1" << endl;
      return 0;
    }
    for (long long int i = 1; i <= n; i++) {
      if (i == 1 && vis[1] == 0)
        cout << "1";
      else {
        cout << vis[i];
      }
    }
    cout << endl;
  } else
    cout << "-1" << endl;
  return 0;
}
