#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
} s[55];
bool cmp(node a, node b) { return a.x < a.y; }
int main() {
  int n, m;
  cin >> n >> m;
  int a[5];
  memset(a, 0, sizeof(a));
  int flag = 1;
  for (int i = 0; i < m; i++) {
    cin >> s[i].x >> s[i].y;
    a[s[i].x] = s[i].y;
  }
  sort(s, s + m, cmp);
  for (int i = 0; i < m; i++) {
    if ((a[s[i].x]) != s[i].y) flag = 0;
  }
  if (flag == 0)
    cout << -1;
  else {
    if (n == 1)
      cout << a[1];
    else if (n == 2) {
      if (a[1] == 0)
        cout << -1;
      else
        cout << a[1] << a[2];
    } else if (n == 3) {
      if (a[1] == 0)
        cout << -1;
      else
        cout << a[1] << a[2] << a[3];
    }
  }
  cout << endl;
  return 0;
}
