#include <bits/stdc++.h>
using namespace std;
int arr[6666];
map<int, int> vis;
signed main() {
  for (int i = 0; i <= 60; i++) arr[i] = -1;
  int n, m;
  cin >> n >> m;
  int f = 1;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    if ((arr[x] != -1 && arr[x] != y)) {
      f = 0;
    }
    vis[y] = 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;
    vis[1] = 1;
  }
  for (int i = 1; i <= n; i++) {
    if (arr[i] != -1)
      cout << arr[i];
    else {
      cout << "0";
    }
  }
  return 0;
}
