#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const long long mod = 1e6;
const int N = 1e3 + 5, M = 35;
const long long INF = 1e15;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
int vis[10];
int main() {
  memset(vis, -1, sizeof vis);
  int n, m;
  cin >> n >> m;
  int flag = 1;
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (vis[x] == -1)
      vis[x] = y;
    else if (y != vis[x]) {
      flag = 0;
    }
  }
  if (!flag) {
    puts("-1");
  } else {
    if (vis[1] == 0) {
      if (n == 1)
        puts("0");
      else {
        puts("-1");
      }
    } else {
      for (int i = 1; i <= n; i++) cout << (vis[i] == -1 ? 0 : vis[i]);
    }
  }
  return 0;
}
