#include <bits/stdc++.h>
using namespace std;
int a[5];
int main() {
  int n, m, ans = 0, i;
  cin >> n >> m;
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (a[x] && a[x] != y) {
      ans = -1;
      break;
    } else {
      a[x] = y;
    }
  }
  if (a[1] == 0) {
    ans = -1;
  }
  if (ans == -1)
    cout << ans;
  else if (ans != -2) {
    for (i = 1; i <= n; i++) cout << a[i];
  }
  return 0;
}
