#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const long long MOD = 1000000007;
using namespace std;
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> z(n, -1);
  int i, j;
  int bad = 0;
  for (i = 0; i < m; i++) {
    int s, c;
    scanf("%d%d", &s, &c);
    s--;
    if (z[s] < 0)
      z[s] = c;
    else if (z[s] != c)
      bad = 1;
  }
  if (bad) {
    printf("-1\n");
    return;
  }
  int a = 0, b = 9;
  if (n == 2) {
    a = 10;
    b = 99;
  }
  if (n == 3) {
    a = 100;
    b = 999;
  }
  vector<int> ans;
  for (j = 0; j < n; j++) {
    if (z[j] >= 0) {
      if (j == 0 && z[j] == 0) bad = 1;
      ans.push_back(z[j]);
    } else {
      if (j == 0 && n != 1)
        ans.push_back(1);
      else
        ans.push_back(0);
    }
  }
  if (bad) {
    printf("-1\n");
    return;
  }
  for (j = 0; j < n; j++) {
    printf("%d", ans[j]);
  }
  printf("\n");
  return;
}
int main(int argc, char* argv[]) {
  solve();
  return 0;
}
