#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> num;
  for (int i = 0; i < n; i++) {
    num.push_back(-2);
  }
  int sc[5][2];
  int temp;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> temp;
      sc[i][j] = temp;
    }
  }
  for (int i = 0; i < m; i++) {
    if (num[sc[i][0] - 1] == -2) {
      num[sc[i][0] - 1] = sc[i][1];
    } else if (num[sc[i][0] - 1] == sc[i][1]) {
    } else if (num[sc[i][0] - 1] != sc[i][1]) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (num[i] == -2) {
      num[i] = 0;
    }
  }
  int ans = 0;
  if (n == 1 & num[0] == 0) {
    cout << 0;
  } else if (n == 2 && num[0] == 0 && num[1] == 0) {
    cout << 0;
  } else if (n == 3 && num[0] == 0 && num[1] == 0 && num[2] == 0) {
    cout << 0;
  } else if (num[0] == 0) {
    cout << -1;
  } else {
    for (int i = 0; i < n; i++) {
      ans += num[i] * pow(10, n - i - 1);
    }
    cout << ans;
  }
  return 0;
}
