#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m1;
  cin >> n >> m1;
  long long f = 0;
  map<long long, long long> m;
  long long arr[n];
  memset(arr, 0, sizeof(arr));
  long long p = 0;
  set<long long> s;
  arr[0] = 1;
  if (m1 == 0 && n > 1) {
    if (n == 1)
      cout << 0;
    else if (n == 2)
      cout << 10;
    else
      cout << 100;
    return 0;
  }
  for (long long i = 0; i < m1; i++) {
    long long x, y;
    cin >> x >> y;
    if (x == 1 && y == 0 && n > 1) f = 1;
    if (s.find(x) != s.end()) {
      if (m[x] != y) f = 1;
    } else {
      m[x] = y;
      s.insert(x);
    }
    arr[x - 1] = y;
  }
  if (f == 1)
    cout << -1;
  else {
    long long x = 0;
    for (long long i = n - 1; i >= 0; i--) {
      x += arr[i] * pow(10, (n - 1 - i));
    }
    cout << x;
  }
}
