#include <bits/stdc++.h>
using namespace std;
int a[10], b[10], c[10], k = 0;
int n, m, x, y;
int main() {
  cin >> n >> m;
  memset(a, 0x3f3f3f3f, sizeof(a));
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    a[x] = min(a[x], y);
    if (x == 1) c[k++] = y;
  }
  sort(c, c + k);
  if (n == 1) {
    if (a[1] == 0x3f3f3f3f)
      cout << -1;
    else
      cout << a[1];
  } else {
    if (a[1] == 0x3f3f3f3f) {
      cout << -1;
    } else {
      if (a[1] != 0) {
        int ans = a[1];
        for (int i = 2; i <= n; i++) {
          if (a[i] != 0x3f3f3f3f) {
            ans = ans * 10 + a[i];
          } else
            ans = ans * 10;
        }
        cout << ans;
      } else {
        for (int i = 0; i < k; i++)
          if (c[i] != 0) {
            a[1] = c[i];
            break;
          }
        if (a[1] == 0)
          cout << -1;
        else {
          int ans = a[1];
          for (int i = 2; i <= n; i++) {
            if (a[i] != 0x3f3f3f3f)
              ans = ans * 10 + a[i];
            else
              ans = ans * 10;
          }
          cout << ans;
        }
      }
    }
  }
  return 0;
}
