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