#include <bits/stdc++.h>
using namespace std;
int n, m, z[2323];
bool vis[2323];
bool flag;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (z[a] != b) {
      if (vis[a] == 1) {
        flag = 1;
        break;
      } else {
        z[a] = b;
        vis[a] = 1;
      }
    }
  }
  if (flag == 1 || z[1] == 0) {
    cout << -1;
    return 0;
  }
  if (vis[1] == 0) z[1] = 0;
  for (int i = 2; i <= n; i++) {
    if (vis[i] == 0) z[i] = 0;
  }
  for (int i = 1; i <= n; i++) cout << z[i];
  return 0;
}
