#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));
  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 (m[x]) {
      if (m[x] != y) f = 1;
    } else
      m[x] = y;
    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));
    }
    long long c = 0;
    while (x) {
      x /= 10;
      c++;
    }
    if (c != n)
      cout << -1;
    else
      cout << x;
  }
}
