#include <bits/stdc++.h>
using namespace std;
long long arr[66];
map<long long, long long> vis;
signed main() {
  for (long long i = 0; i <= 6; i++) arr[i] = -1;
  long long n, m;
  cin >> n >> m;
  long long f = 1;
  for (long long i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    if (vis[x] && arr[x] != y) {
      f = 0;
    }
    vis[x] = 1;
    arr[x] = y;
  }
  if (!f) {
    printf("-1");
    return 0;
  }
  if (arr[1] == 0) {
    if (n == 1) {
      cout << "0";
    } else {
      cout << "-1";
    }
    return 0;
  }
  if (arr[1] == -1) arr[1] = 1;
  for (long long i = 1; i <= n; i++) {
    if (arr[i] != -1)
      cout << arr[i];
    else
      cout << "0";
  }
  return 0;
}
