import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.util.ArrayDeque;
import java.io.PrintWriter;
import java.util.TreeSet;
import java.util.AbstractCollection;
import java.util.StringTokenizer;
import java.util.Collection;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Zyflair Griffane
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		PandaScanner in = new PandaScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		J solver = new J();
		solver.solve(1, in, out);
		out.close();
	}
}

class J {
    public void solve(int testNumber, PandaScanner in, PrintWriter out) {
        int h = in.nextInt();
        int w = in.nextInt();
        if (h * w == 1) {
            out.println(1);
            return;
        }
        if (Math.max(h, w) < 3 || h * w <= 3) {
            out.println(-1);
            return;
        }
        int[][] res = new int[h][w];
        ArrayDeque<Integer> lst = new ArrayDeque<>();
        for (int start = 2; start >= 1; start--) {
            ArrayDeque<Integer> q = new ArrayDeque<>();
            int curr = start;
            while (curr <= h * w) {
                q.addLast(curr);
                curr += 2;
            }
            if (h == 2 && start == 1) {
                q.addFirst(q.pollLast());
            }
            lst.addAll(q);
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                res[i][j] = lst.poll();
            }
            out.println(ArrayUtil.toString(res[i]));
        }
    }
}

class PandaScanner {
    public BufferedReader br;
    public StringTokenizer st;
    public InputStream in;

    public PandaScanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(this.in = in));
    }

    public String nextLine() {
        try {
            return br.readLine();
        }
        catch (Exception e) {
            return null;
        }
    }

    public String next() {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(nextLine().trim());
            return next();
        }
        return st.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    }

class ArrayUtil {

    public static<T> String toString(int[] arr) {
        StringBuilder res = new StringBuilder();
        for (int i: arr) {
            res.append(i);
            res.append(' ');
        }
        return res.toString();
    }

    }


import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int t = 1;
        Task solver = new Task();
        while ((t --) > 0)
            solver.solve(in, out);
        out.close();
    }
}
class Task{
    void solve (InputReader cin , PrintWriter cout) {
        int n = cin.nextInt() , m = cin.nextInt();
        if (n == 1 && m == 1) {
            cout.println(1);
            return ;
        }
        if (n + m <= 4) {
            cout.println(-1);
            return ;
        }
        if (n == 1) {
            for (int i = 1 , j = m / 2 + 1 , k = 1 ; i <= m ; i ++) {
                if (i % 2 == 1) {
                    cout.print(j + " ");
                    j ++;
                }
                else {
                    cout.print(k + " ");
                    k ++;
                }
            }
            cout.println();
            return ;
        }
        if (m == 1) {
            for (int i = 1 , j = n / 2 + 1 , k = 1 ; i <= n ; i ++) {
                if (i % 2 == 1) {
                    cout.println(j);
                    j ++;
                }
                else {
                    cout.println(k);
                    k ++;
                }
            }
            return ;
        }
        int a[][] = new int [105][105];
        int b[][] = new int [105][105];
        for (int i = 0 ; i < n ; i ++) {
            int k = i + 1;
            for (int j = 0 ; j < m ; j ++ , k += n) {
                a[i][j] = k;
            }
        }
        for (int i = 0 ; i < n ; i ++) {
            for (int j = 0 ; j < m ; j ++) {
                b[i][j] = a[i][(j + i) % m];
            }
        }
        for (int i = 0 ; i < n ; i ++) {
            for (int j = 0 ; j < m ; j ++)
                cout.print(b[i][j] + " ");
            cout.println();
        }
    }
}
class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		int t = 1;
		Task solver = new Task();
		while ((t --) > 0)
			solver.solve(in, out);
		out.close();
	}
}
class Task{
	void solve (InputReader cin , PrintWriter cout) {
		int n = cin.nextInt() , m = cin.nextInt();
		if (n == 1 && m == 1) {
			cout.println(1);
			return ;
		}
		if (n + m <= 4) {
			cout.println(-1);
			return ;
		}
		if (n == 1) {
			for (int i = 1 , j = m / 2 + 1 , k = 1 ; i <= m ; i ++) {
				if (i % 2 == 1) {
					cout.print(j + " ");
					j ++;
				}
				else {
					cout.print(k + " ");
					k ++;
				}
			}
			cout.println();
			return ;
		}
		if (m == 1) {
			for (int i = 1 , j = n / 2 + 1 , k = 1 ; i <= n ; i ++) {
				if (i % 2 == 1) {
					cout.println(j);
					j ++;
				}
				else {
					cout.println(k);
					k ++;
				}
			}
			return ;
		}
		int a[][] = new int [105][105];
		int b[][] = new int [105][105];
		for (int i = 0 ; i < n ; i ++) {
			int k = i + 1;
			for (int j = 0 ; j < m ; j ++ , k += m) {
				a[i][j] = k;
			}
		}
		for (int i = 0 ; i < n ; i ++) {
			for (int j = 0 ; j < m ; j ++) {
				b[i][j] = a[i][(j + i) % m];
			}
		}
		for (int i = 0 ; i < n ; i ++) {
			for (int j = 0 ; j < m ; j ++)
				cout.print(b[i][j] + " ");
			cout.println();
		}
	}
}
class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
    	return Long.parseLong(next());
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
    public BigInteger nextBigInteger() {
    	return new BigInteger(next());
    }
}


import java.util.Scanner;

public class J {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        boolean flag = false;

        if (n < m) {
            n = n ^ m;
            m = n ^ m;
            n = n ^ m;
            flag = true;
        }

        if (n * m == 1) {
            System.out.println(1);
            return;
        }

        if (m == 1 && n <= 3) {
            System.out.println(-1);
            return;
        }

        if (n == 2 && m == 2) {
            System.out.println(-1);
            return;
        }

        int[][] fill = new int[n][m];

        if (n == 3 && m == 2) {
            fill[0][0] = 3;
            fill[0][1] = 5;
            fill[1][0] = 6;
            fill[1][1] = 1;
            fill[2][0] = 2;
            fill[2][1] = 4;
        }

        else if (m == 1) {
            int p = n - 1;
            int v = 2;
            while (p >= 0) {
                fill[p][0] = v;
                v += 2;
                if (v > n) {
                    v = 1;
                }
                p--;
            }
        }

        else {
            int v = 1;
            for( int i = 0; i < n ; i++){
              for( int j = 0; j < m; j++){
                 fill[i][j] = v;
                 v += 2;
                 if( v > m*n){
                  v = 2;
                 }
              }
            }
        }

        if(!flag){
           for( int i = 0; i < n; i++){
             for( int j = 0; j < m; j++){
               System.out.print(fill[i][j] + " ");
             }
             System.out.println();
           }
        }
        else{
           for( int i = 0; i < m; i++){
             for( int j = 0; j < n; j++){
               System.out.print(fill[j][i] + " ");
             }
             System.out.println();
           }
        }
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class A {
	public static void main(String[] args) throws Exception {
		MScanner sc = new MScanner();
		PrintWriter out = new PrintWriter(System.out);
		int H = sc.nextInt();
		int W = sc.nextInt();
		if(H==1&&W==1){
			out.println("1");
			out.close();
		}
		if(H*W==4&&H+W==5){
			out.println("3 1 4 2 ");
			out.close();
		}
		if(Math.max(H, W)<3 || H*W < 4){
			out.println("-1");
			out.close();
		}
		if(H==3&&W==2){
			out.println("1 4 5 2 3 6  ");
			out.close();
		}
		int[][] grid = new int[H][W];
		int cur =1;
		int times = 0;
		LinkedList<Integer> slack = new LinkedList<Integer>();
		for(int a=0;a<H;a++){
			for(int b=0;b<W;b++){
				grid[a][b]=cur;
				if(times==2){
					grid[a][b]=slack.poll();
					continue;
				}
				if(a!=0&&Math.abs(grid[a][b]-grid[a-1][b])==1){
					slack.add(grid[a][b]);
					b--;
				}
				cur+=2;
				if(cur>H*W){
					times++;
					cur=2;
				}
			}
		}
		for(int a=0;a<H;a++){
			for(int b=0;b<W;b++){
				out.print(grid[a][b]+" ");
			}
			out.println();
		}
		out.close();
	}

	static class MScanner{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public MScanner() throws Exception{
			stream = System.in;

		}
		int read(){
			if(numChars==-1)
				throw new InputMismatchException();
			if(curChar>=numChars){
				curChar = 0;
				try{
					numChars = stream.read(buf);
				} catch (IOException e){
					throw new InputMismatchException();
				}
				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c){
			return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
		}
		boolean isEndline(int c){
			return c=='\n'||c=='\r'||c==-1;
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		int[] nextInt(int N){
			int[] ret = new int[N];
			for(int a=0;a<N;a++)
				ret[a] = nextInt();
			return ret;
		}
		int[][] nextInt(int N, int M){
			int[][] ret = new int[N][M];
			for(int a=0;a<N;a++)
				ret[a] = nextInt(M);
			return ret;
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		long[] nextLong(int N){
			long[] ret = new long[N];
			for(int a=0;a<N;a++)
				ret[a] = nextLong();
			return ret;
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		double[] nextDouble(int N){
			double[] ret = new double[N];
			for(int a=0;a<N;a++)
				ret[a] = nextDouble();
			return ret;
		}
		String next(){
			int c = read();
			while(isSpaceChar(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c=read();
			} while(!isSpaceChar(c));
			return res.toString();
		}
		String[] next(int N){
			String[] ret = new String[N];
			for(int a=0;a<N;a++)
				ret[a] = next();
			return ret;
		}
		String nextLine(){
			int c = read();
			while(isEndline(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c = read();
			}while(!isEndline(c));
			return res.toString();
		}
		String[] nextLine(int N){
			String[] ret = new String[N];
			for(int a=0;a<N;a++)
				ret[a] = nextLine();
			return ret;
		}

	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class A {
	public static void main(String[] args) throws Exception {
		MScanner sc = new MScanner();
		PrintWriter out = new PrintWriter(System.out);
		int H = sc.nextInt();
		int W = sc.nextInt();
		if(H==1&&W==1){
			out.println("1");
			out.close();
		}
		if(Math.max(H, W)<3 || H*W < 4){
			out.println("-1");
			out.close();
		}
		int[][] grid = new int[H][W];
		int cur =1;
		int times = 0;
		LinkedList<Integer> slack = new LinkedList<Integer>();
		for(int a=0;a<H;a++){
			for(int b=0;b<W;b++){
				grid[a][b]=cur;
				if(times==2){
					grid[a][b]=slack.poll();
					continue;
				}
				if(a!=0&&Math.abs(grid[a][b]-grid[a-1][b])==1){
					slack.add(grid[a][b]);
					b--;
				}
				cur+=2;
				if(cur>H*W){
					times++;
					cur=2;
				}
			}
		}
		for(int a=0;a<H;a++){
			for(int b=0;b<W;b++){
				out.print(grid[a][b]+" ");
			}
			out.println();
		}
		out.close();
	}

	static class MScanner{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public MScanner() throws Exception{
			stream = System.in;

		}
		int read(){
			if(numChars==-1)
				throw new InputMismatchException();
			if(curChar>=numChars){
				curChar = 0;
				try{
					numChars = stream.read(buf);
				} catch (IOException e){
					throw new InputMismatchException();
				}
				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c){
			return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
		}
		boolean isEndline(int c){
			return c=='\n'||c=='\r'||c==-1;
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		int[] nextInt(int N){
			int[] ret = new int[N];
			for(int a=0;a<N;a++)
				ret[a] = nextInt();
			return ret;
		}
		int[][] nextInt(int N, int M){
			int[][] ret = new int[N][M];
			for(int a=0;a<N;a++)
				ret[a] = nextInt(M);
			return ret;
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		long[] nextLong(int N){
			long[] ret = new long[N];
			for(int a=0;a<N;a++)
				ret[a] = nextLong();
			return ret;
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		double[] nextDouble(int N){
			double[] ret = new double[N];
			for(int a=0;a<N;a++)
				ret[a] = nextDouble();
			return ret;
		}
		String next(){
			int c = read();
			while(isSpaceChar(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c=read();
			} while(!isSpaceChar(c));
			return res.toString();
		}
		String[] next(int N){
			String[] ret = new String[N];
			for(int a=0;a<N;a++)
				ret[a] = next();
			return ret;
		}
		String nextLine(){
			int c = read();
			while(isEndline(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c = read();
			}while(!isEndline(c));
			return res.toString();
		}
		String[] nextLine(int N){
			String[] ret = new String[N];
			for(int a=0;a<N;a++)
				ret[a] = nextLine();
			return ret;
		}

	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class A {
	public static void main(String[] args) throws Exception {
		MScanner sc = new MScanner();
		PrintWriter out = new PrintWriter(System.out);
		int H = sc.nextInt();
		int W = sc.nextInt();
		if(H==1&&W==1){
			out.println("1");
			out.close();
		}
		if(H*W==4&&H+W==5){
			out.println("3 1 4 2 ");
			out.close();
		}
		if(Math.max(H, W)<3 || H*W < 4){
			out.println("-1");
			out.close();
		}
		int[][] grid = new int[H][W];
		int cur =1;
		int times = 0;
		LinkedList<Integer> slack = new LinkedList<Integer>();
		for(int a=0;a<H;a++){
			for(int b=0;b<W;b++){
				grid[a][b]=cur;
				if(times==2){
					grid[a][b]=slack.poll();
					continue;
				}
				if(a!=0&&Math.abs(grid[a][b]-grid[a-1][b])==1){
					slack.add(grid[a][b]);
					b--;
				}
				cur+=2;
				if(cur>H*W){
					times++;
					cur=2;
				}
			}
		}
		for(int a=0;a<H;a++){
			for(int b=0;b<W;b++){
				out.print(grid[a][b]+" ");
			}
			out.println();
		}
		out.close();
	}

	static class MScanner{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public MScanner() throws Exception{
			stream = System.in;

		}
		int read(){
			if(numChars==-1)
				throw new InputMismatchException();
			if(curChar>=numChars){
				curChar = 0;
				try{
					numChars = stream.read(buf);
				} catch (IOException e){
					throw new InputMismatchException();
				}
				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c){
			return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
		}
		boolean isEndline(int c){
			return c=='\n'||c=='\r'||c==-1;
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		int[] nextInt(int N){
			int[] ret = new int[N];
			for(int a=0;a<N;a++)
				ret[a] = nextInt();
			return ret;
		}
		int[][] nextInt(int N, int M){
			int[][] ret = new int[N][M];
			for(int a=0;a<N;a++)
				ret[a] = nextInt(M);
			return ret;
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		long[] nextLong(int N){
			long[] ret = new long[N];
			for(int a=0;a<N;a++)
				ret[a] = nextLong();
			return ret;
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		double[] nextDouble(int N){
			double[] ret = new double[N];
			for(int a=0;a<N;a++)
				ret[a] = nextDouble();
			return ret;
		}
		String next(){
			int c = read();
			while(isSpaceChar(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c=read();
			} while(!isSpaceChar(c));
			return res.toString();
		}
		String[] next(int N){
			String[] ret = new String[N];
			for(int a=0;a<N;a++)
				ret[a] = next();
			return ret;
		}
		String nextLine(){
			int c = read();
			while(isEndline(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c = read();
			}while(!isEndline(c));
			return res.toString();
		}
		String[] nextLine(int N){
			String[] ret = new String[N];
			for(int a=0;a<N;a++)
				ret[a] = nextLine();
			return ret;
		}

	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.LinkedList;

public class A {
	public static void main(String[] args) throws Exception {
		MScanner sc = new MScanner();
		PrintWriter out = new PrintWriter(System.out);
		int H = sc.nextInt();
		int W = sc.nextInt();
		if(Math.max(H, W)<3 || H*W < 4){
			out.println("-1");
			out.close();
		}
		int[][] grid = new int[H][W];
		int cur =1;
		int times = 0;
		LinkedList<Integer> slack = new LinkedList<Integer>();
		for(int a=0;a<H;a++){
			for(int b=0;b<W;b++){
				grid[a][b]=cur;
				if(times==2){
					grid[a][b]=slack.poll();
					continue;
				}
				if(a!=0&&Math.abs(grid[a][b]-grid[a-1][b])==1){
					slack.add(grid[a][b]);
					b--;
				}
				cur+=2;
				if(cur>H*W){
					times++;
					cur=2;
				}
			}
		}
		for(int a=0;a<H;a++){
			for(int b=0;b<W;b++){
				out.print(grid[a][b]+" ");
			}
			out.println();
		}
		out.close();
	}

	static class MScanner{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public MScanner() throws Exception{
			stream = System.in;

		}
		int read(){
			if(numChars==-1)
				throw new InputMismatchException();
			if(curChar>=numChars){
				curChar = 0;
				try{
					numChars = stream.read(buf);
				} catch (IOException e){
					throw new InputMismatchException();
				}
				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c){
			return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
		}
		boolean isEndline(int c){
			return c=='\n'||c=='\r'||c==-1;
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		int[] nextInt(int N){
			int[] ret = new int[N];
			for(int a=0;a<N;a++)
				ret[a] = nextInt();
			return ret;
		}
		int[][] nextInt(int N, int M){
			int[][] ret = new int[N][M];
			for(int a=0;a<N;a++)
				ret[a] = nextInt(M);
			return ret;
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		long[] nextLong(int N){
			long[] ret = new long[N];
			for(int a=0;a<N;a++)
				ret[a] = nextLong();
			return ret;
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		double[] nextDouble(int N){
			double[] ret = new double[N];
			for(int a=0;a<N;a++)
				ret[a] = nextDouble();
			return ret;
		}
		String next(){
			int c = read();
			while(isSpaceChar(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c=read();
			} while(!isSpaceChar(c));
			return res.toString();
		}
		String[] next(int N){
			String[] ret = new String[N];
			for(int a=0;a<N;a++)
				ret[a] = next();
			return ret;
		}
		String nextLine(){
			int c = read();
			while(isEndline(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c = read();
			}while(!isEndline(c));
			return res.toString();
		}
		String[] nextLine(int N){
			String[] ret = new String[N];
			for(int a=0;a<N;a++)
				ret[a] = nextLine();
			return ret;
		}

	}
}


#include <cstdio>
#include <algorithm>

const int MAXN = 202;

int arr[MAXN][MAXN];

int main() {
    int n, m; scanf("%d%d", &n, &m);

    int nn = n, mm = m;
    if (nn > mm) std::swap(nn, mm);
    if (nn == 1 and mm == 1) {
        puts("1");
        return 0;
    }

    if ((nn == 1 and mm <= 3) or
        (nn == 2 and mm <= 2)) {
        puts("-1");
        return 0;
    }

    int cnt = 0;
    if (n > m) {
        if (m == 1) {
            for (int i = 1; i < n; i += 2)
                arr[i][0] = ++cnt;
            for (int i = 0; i < n; i += 2)
                arr[i][0] = ++cnt;
        } else {
            for (int j = 0; j < m; ++j)
                for (int i = 0; i < n; ++i)
                    arr[i][(j+i)%m] = ++cnt;
        }
    } else {
        if (n == 1) {
            for (int j = 1; j < m; j += 2)
                arr[0][j] = ++cnt;
            for (int j = 0; j < m; j += 2)
                arr[0][j] = ++cnt;
        } else {
            for (int i = 0; i < n; ++i)
                for (int j = 0; j < m; ++j)
                    arr[(j+i)%n][j] = ++cnt;
        }
    }

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            printf("%d%c", arr[i][j], " \n"[j+1==m]);

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int n, m;
int a[110][110];

int main() {
    cin >> n >> m;

    if (n+m==3 or n+m==4) {
        cout << "-1" << endl;
    }

    else{
        int num=2;
        if (n>=m) {
            for (int i = 1; i <= n; i++)
                for (int j = 1; j <= m; j++){
                    if (num > m*n) {
                        num=1;
                    }
                    a[i][j]=num;
                    num += 2;
                }
        }
        else
            for (int j = 1; j <= m; j++) {
                for (int i = 1; i <= n; i++){
                    if (num > m*n) {
                        num = 1;
                    }
                    a[i][j] = num;
                    num += 2;
                }
            }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++){
                cout << a[i][j];
                if (j == m) {
                    cout << "\n";
                }
                else {
                    cout << " ";
                }
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=109;
int n,m,t1,t2=1;
int main()
{
	cin>>n>>m;
	if (n==m && n==1) return cout<<1,0;
	if (m+n<5) return cout<<-1,0;
	t1=n*m/2+1;
	for (int i=0;i<n;i++,cout<<'\n')
		for (int j=0;j<m;j++)
			if ((i+j)%2==0)
				cout<<t1<<" ",t1++;
			else
				cout<<t2<<" ",t2++;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long lint;
typedef long double ldouble;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	bool rev=n>m;
	if (rev) swap(n, m);
	vector<vector<int>>vet(n, vector<int>(m));
	if ((n==1 and (m==2 or m==3)) or (n==2 and m==2)) printf("-1\n");
	else {
		if (m>3) {
			for (int i=0; i<m; i++) vet[0][i]=i<m/2?2*i+2:(i-m/2)*2+1;
			for (int i=1; i<n; i++) for (int j=0; j<m; j++) vet[i][j]=vet[i-1][j]+m;
		} else {
			if (n==2) vet={{1, 5, 3}, {4, 2, 6}};
			else vet={{1, 4, 7}, {8, 2, 5}, {6, 9, 3}};
		}
		if (rev) for (int i=0; i<m; i++) {
			for (int j=0; j<n; j++) printf("%d ", vet[j][i]);
			printf("\n");
		} else for (auto i:vet) {
			for (int j: i) printf("%d ", j);
			printf("\n");
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long lint;
typedef long double ldouble;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	bool rev=n>m;
	if (rev) swap(n, m);
	vector<vector<int>>vet(n, vector<int>(m));
	if ((n==1 and (m==2 or m==3)) or (n==2 and m==2)) printf("-1\n");
	else {
		if (m==1) vet[0][0]=1;
		else if (m>3) {
			for (int i=0; i<m; i++) vet[0][i]=i<m/2?2*i+2:(i-m/2)*2+1;
			for (int i=1; i<n; i++) for (int j=0; j<m; j++) vet[i][j]=vet[i-1][j]+m;
		} else {
			if (n==2) vet={{1, 5, 3}, {4, 2, 6}};
			else vet={{1, 4, 7}, {8, 2, 5}, {6, 9, 3}};
		}
		if (rev) for (int i=0; i<m; i++) {
			for (int j=0; j<n; j++) printf("%d ", vet[j][i]);
			printf("\n");
		} else for (auto i:vet) {
			for (int j: i) printf("%d ", j);
			printf("\n");
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long lint;
typedef long double ldouble;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	bool rev=n>m;
	if (rev) swap(n, m);
	vector<vector<int>>vet(n, vector<int>(m));
	if ((n==1 and (m==2 or m==3)) or (n==2 and m==2)) printf("-1\n");
	else {
		if (n==1 and m==4) vet[0]={2, 4, 1, 3};
		else for (int i=0; i<n; i++) {
			int l=m*i+1, r=m*(i+1);
			for (int j=0; j<m; j++) {
				if (l+2*j<=r) vet[i][j]=l+2*j;
				else if (l+2*(j-1)<=r) vet[i][j]=l+1;
				else vet[i][j]=vet[i][j-1]+2;
			}
		}
		if (rev) for (int i=0; i<m; i++) {
			for (int j=0; j<n; j++) printf("%d ", vet[j][i]);
			printf("\n");
		} else for (int i=0; i<n; i++) {
			for (int j=0; j<m; j++) printf("%d ", vet[i][j]);
			printf("\n");
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define vi          vector<int>
#define Max(a,b)    ((a)>(b)?(a):(b))
#define Min(a,b)    ((a)<(b)?(a):(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define all(a)      a.begin(),a.end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define pii         pair<int,int>

using namespace std;
bool used[10000005];
int ans[105];
bool comp(pair<pii,int>a,pair<pii,int>b){
    if(a.F.S==b.F.S)return a.F.F<b.F.F;
    return a.F.S<b.F.S;
}
void solve(){
    int a,b;
    cin>>a>>b;
    int x[a][b];
    int cur=1;
    if(a>3){
        rep(i,0,b){
            rep(j,a/2,a){
                x[j][i]=cur;
                cur++;
                if(a%2==0 || j!=a-1){
                    x[j-a/2][i]=cur;
                    cur++;
                }
            }
        }
    }
    else if(b>3){
        rep(i,0,a){
            rep(j,b/2,b){
                x[i][j]=cur;
                cur++;
                if(b%2==0 || j!=b-1){
                    x[i][j-b/2]=cur;
                    cur++;
                }
            }
        }
    }
    else{
        if(a==1 && b==1){
            cout<<1;
            return;
        }
        if(a<=2 && b<=2){
            cout<<-1;
            return;
        }
        else if(b==1 || a==1){
            cout<<-1;
            return;
        }
        else if(a==2){
            cout<<"3 6 2\n5 1 4";
            return;
        }
        else if(b==2){
            cout<<"3 5\n6 1\n2 4";
            return;
        }
        else{
            cout<<"2 8 3"<<endl;
            cout<<"4 1 5"<<endl;
            cout<<"6 9 7"<<endl;
            return;
        }
    }
    rep(i,0,a){
        rep(j,0,b){
            cout<<x[i][j]<<" ";
        }
        cout<<endl;
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define vi          vector<int>
#define Max(a,b)    ((a)>(b)?(a):(b))
#define Min(a,b)    ((a)<(b)?(a):(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define all(a)      a.begin(),a.end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define pii         pair<int,int>

using namespace std;
bool used[10000005];
int ans[105];
bool comp(pair<pii,int>a,pair<pii,int>b){
    if(a.F.S==b.F.S)return a.F.F<b.F.F;
    return a.F.S<b.F.S;
}
void solve(){
    int a,b;
    cin>>a>>b;
    int x[a][b];
    int cur=1;
    if(a>3){
        rep(i,0,b){
            rep(j,0,(a+1)/2){
                x[j][i]=cur;
                cur++;
                if(j+(a+1)/2<a){
                    x[j+(a+1)/2][i]=cur;
                    cur++;
                }
            }
        }
    }
    else if(b>3){
        rep(i,0,a){
            rep(j,0,(b+1)/2){
                x[i][j]=cur;
                cur++;
                if(j+(b+1)/2<b){
                    x[i][j+(b+1)/2]=cur;
                    cur++;
                }
            }
        }
    }
    else{
        if(a==1 && b==1){
            cout<<1;
            return;
        }
        if(a<=2 && b<=2){
            cout<<-1;
            return;
        }
        else if(b==1 || a==1){
            cout<<-1;
            return;
        }
        else if(a==2){
            cout<<"3 6 2\n5 1 4";
            return;
        }
        else if(b==2){
            cout<<"3 5\n6 1\n2 4";
            return;
        }
        else{
            cout<<"2 8 3"<<endl;
            cout<<"4 1 5"<<endl;
            cout<<"6 9 7"<<endl;
            return;
        }
    }
    rep(i,0,a){
        rep(j,0,b){
            cout<<x[i][j]<<" ";
        }
        cout<<endl;
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define vi          vector<int>
#define Max(a,b)    ((a)>(b)?(a):(b))
#define Min(a,b)    ((a)<(b)?(a):(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define all(a)      a.begin(),a.end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define pii         pair<int,int>

using namespace std;
bool used[10000005];
int ans[105];
bool comp(pair<pii,int>a,pair<pii,int>b){
    if(a.F.S==b.F.S)return a.F.F<b.F.F;
    return a.F.S<b.F.S;
}
void solve(){
    int a,b;
    cin>>a>>b;
    int x[a][b];
    int cur=1;
    if(a>3){
        rep(i,0,b){
            rep(j,0,(a+1)/2){
                x[j][i]=cur;
                cur++;
                if(j+(a+1)/2<a){
                    x[j+(a+1)/2][i]=cur;
                    cur++;
                }
            }
        }
    }
    else if(b>3){
        rep(i,0,a){
            rep(j,0,(b+1)/2){
                x[i][j]=cur;
                cur++;
                if(j+(b+1)/2<b){
                    x[i][j+(b+1)/2]=cur;
                    cur++;
                }
            }
        }
    }
    else{
        if(a<=2 && b<=2){
            cout<<-1;
            return;
        }
        else if(b==1 || a==1){
            cout<<-1;
            return;
        }
        else if(a==2){
            cout<<"3 6 2\n5 1 4";
            return;
        }
        else if(b==2){
            cout<<"3 5\n6 1\n2 4";
            return;
        }
        else{
            cout<<"2 8 3"<<endl;
            cout<<"4 1 5"<<endl;
            cout<<"6 9 7"<<endl;
            return;
        }
    }
    rep(i,0,a){
        rep(j,0,b){
            cout<<x[i][j]<<" ";
        }
        cout<<endl;
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


N = int(input())

stk = [1]
x = 0
flag = 1

def check(x):
	if x < 2 **32:
		return True
	return False

def multcheck(stk):
	mult = 1
	for bar in stk:
		mult *= bar
		if mult >= 2**32:
			return False
	return mult

for n in range(N):
	cmd = input().split()
	print (stk)
	if cmd[0] == 'add':
		mlt = multcheck(stk)
		if not mlt:
			flag = 0
			break
		x += mlt
		if not check(x):
			flag = 0
			break
		continue
	if cmd[0] == 'for':
		stk.append(int(cmd[1]))
		continue
	if cmd[0] == 'end':
		stk.pop()
		continue

if flag:
	print(int(x))
else:
	print("OVERFLOW!!!")


N = int(input())

stk = [1]
x = 0
flag = 1

def check(x):
	if x < 2 **32:
		return True
	return False

def multcheck(stk):
	mult = 1
	for bar in stk:
		mult *= bar
		if mult >= 2**32:
			return False
	return bar

for n in range(N):
	cmd = input().split()
	if cmd[0] == 'add':
		mlt = multcheck(stk)
		if not mlt:
			flag = 0
			break
		x += mlt
		if not check(x):
			flag = 0
			break
		continue
	if cmd[0] == 'for':
		stk.append(int(cmd[1]))
		continue
	if cmd[0] == 'end':
		stk.pop()
		continue

if flag:
	print(int(x))
else:
	print("OVERFLOW!!!")


N = int(input())

stk = [1]
x = 0
flag = 1

def check(x):
	if x < 2 **32:
		return True
	return False

def multcheck(stk):
	mult = 1
	for bar in stk:
		mult *= bar
		if mult >= 2**32:
			return False
	return mult

for n in range(N):
	cmd = input().split()
	if cmd[0] == 'add':
		mlt = multcheck(stk)
		if not mlt:
			flag = 0
			break
		x += mlt
		if not check(x):
			flag = 0
			break
		continue
	if cmd[0] == 'for':
		stk.append(int(cmd[1]))
		continue
	if cmd[0] == 'end':
		stk.pop()
		continue

if flag:
	print(int(x))
else:
	print("OVERFLOW!!!")


N = int(input())

stk = [1]
x = 0
flag = 1

def check(x):
	if x < 2 **32:
		return True
	return False

def multcheck(stk):
	mult = 1
	for bar in stk:
		mult *= bar
		if mult >= 2**32:
			return False
	return mult

for n in range(N):
	cmd = input()
	if cmd[0] == 'a':
		mlt = multcheck(stk)
		if not mlt:
			flag = 0
			break
		x += mlt
		if not check(x):
			flag = 0
			break
		continue
	if cmd[0] == 'f':
		m = int(cmd[4:])
		if m == 1:
			continue
		stk.append(m)
		continue
	if cmd[0] == 'e':
		stk.pop()
		continue

if flag:
	print(int(x))
else:
	print("OVERFLOW!!!")


N = int(input())

stk = [1]
x = 0
mult = 1
flag = 1

def check(x):
	if x < 2 **32:
		return True
	print("OVERFLOW!!!")
	return False

for n in range(N):
	cmd = input().split()
	if cmd[0] == 'add':
		x += mult
		if not check(x):
			flag = 0
			break;
		continue
	if cmd[0] == 'for':
		mult *= int(cmd[1])
		stk.append(int(cmd[1]))
		continue
	if cmd[0] == 'end':
		mult /= stk.pop()
		continue
if flag:
	print(int(x))


from collections import deque

num_lines = int(input())

loop_stack = deque()
total_value = 0
loop_value = 0
overflow = False

for _ in range(num_lines):
    if total_value >= 2**32:
        overflow = True
        break
    line = input()
    if line == "add":  # add
        loop_value += 1
    elif line[:3] == "for":  # loop
        N = int(line.strip().split()[1])
        loop_stack.append(N)
    else:  # end loop
        loop_value *= loop_stack.pop()

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0

if overflow:
    print("OVERFLOW!!!")
else:
    print(total_value)


from collections import deque

num_lines = int(input())
loop_stack = deque()

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0
        while (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()
        loop_iters = int(k.strip().split()[1])
        loop_sum *= loop_iters
        loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        else:
            loop_stack.appendleft(1)

ans = sum(loop_stack)
print(ans if ans < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()
total_sum = 0

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0  # integer equivalent of the loop
        if (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])   # the N in [for N]
        loop_sum *= loop_iters
        if len(loop_stack) == 0:
            total_sum += loop_sum
        else:
            if isinstance(loop_stack[0], int):
                loop_stack[0] += loop_sum
            else:
                loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        elif len(loop_stack) > 0:
            loop_stack.appendleft(1)
        else:
            total_sum += 1

ans = total_sum
print(ans if ans < 2**32 else "OVERFLOW!!!")


from collections import deque

n, k = [int(a) for a in input().strip().split()]

powers = deque()
for a in input().strip().split():
    powers.append(int(a))

num_wins = {x: 0 for x in powers}
if n == 1:
    print(powers[0])
elif k > n:
    print(max(powers))
else:
    current = None
    curr_max_wins = -float("inf")
    while (curr_max_wins < k):

        if current is None:
            current = powers.popleft()
        else:
            challenger = powers.popleft()

            if challenger > current:
                powers.append(current)
                num_wins[challenger] += 1
                current = challenger

            else:
                powers.append(challenger)
                num_wins[current] += 1

            for i, j in num_wins.items():
                if j > curr_max_wins:
                    curr_max_wins = j

    print(current)


from collections import deque

num_lines = int(input())
loop_stack = deque()
overflow = False

for j in range(num_lines):
    line = input()
    if not overflow:
        if line[:3] == "for":
            loop_stack.appendleft(line)
        elif line[:3] == "end":
            # keep going until you pop the start of loop, then push the sum
            k = loop_stack.popleft()
            loop_sum = 0  # integer equivalent of the loop
            if (isinstance(k, int)):
                loop_sum += k
                k = loop_stack.popleft()

            loop_iters = int(k.strip().split()[1])   # the N in [for N]
            loop_sum *= loop_iters
            if loop_sum > 0:
                if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                    loop_stack[0] += loop_sum
                else:
                    loop_stack.appendleft(loop_sum)
        else:  # add
            if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                loop_stack[0] += 1
            else:
                loop_stack.appendleft(1)

    if (len(loop_stack) > 0 and isinstance(loop_stack[0], int) and loop_stack[0] > 2**32):
        overflow = True
        break

k = sum(loop_stack)
if k > 2**32:
    overflow = True
if overflow:
    print("OVERFLOW!!!")
else:
    print(k)


from collections import deque

num_lines = int(input())
loop_stack = deque()
overflow = False

for j in range(num_lines):
    line = input()
    if not overflow:
        if line[:3] == "for":
            loop_stack.appendleft(line)
        elif line[:3] == "end":
            # keep going until you pop the start of loop, then push the sum
            k = loop_stack.popleft()
            loop_sum = 0  # integer equivalent of the loop
            if (isinstance(k, int)):
                loop_sum += k
                k = loop_stack.popleft()

            loop_iters = int(k.strip().split()[1])   # the N in [for N]
            loop_sum *= loop_iters
            if loop_sum > 0:
                if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                    loop_stack[0] += loop_sum
                else:
                    loop_stack.appendleft(loop_sum)
        else:  # add
            if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                loop_stack[0] += 1
            else:
                loop_stack.appendleft(1)

    if (len(loop_stack) > 0 and isinstance(loop_stack[0], int) and loop_stack[0] > 2**32):
        overflow = True
        break

if overflow:
    print("OVERFLOW!!!")
else:
    print(sum(loop_stack))


from collections import deque

num_lines = int(input())
loop_stack = deque()

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0
        while (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])
        loop_sum *= loop_iters
        if loop_sum > 0:
            loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        else:
            loop_stack.appendleft(1)

ans = sum(loop_stack)
print(ans if ans < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()
overflow = False

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0  # integer equivalent of the loop
        if (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])   # the N in [for N]
        loop_sum *= loop_iters
        if loop_sum > 0:
            if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                loop_stack[0] += loop_sum
            else:
                loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        else:
            loop_stack.appendleft(1)
    print(loop_stack)

    if (len(loop_stack) > 0 and isinstance(loop_stack[0], int) and loop_stack[0] > 2**32):
        overflow = True
        break

if overflow:
    print("OVERFLOW!!!")
else:
    print(sum(loop_stack))


from collections import deque

num_lines = int(input())
loop_stack = deque()
total_sum = 0
overflow = False

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0  # integer equivalent of the loop
        if (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])   # the N in [for N]
        loop_sum *= loop_iters
        if len(loop_stack) == 0:
            total_sum += loop_sum
        else:
            if isinstance(loop_stack[0], int):
                loop_stack[0] += loop_sum
            else:
                loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        elif len(loop_stack) > 0:
            loop_stack.appendleft(1)
        else:
            total_sum += 1
    if total_sum > 2**32 or (len(loop_stack) > 0 and loop_stack[0] > 2**32):
        overflow = True
        break

print(total_sum if not overflow else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())

loop_stack = deque()
total_value = 0
loop_value = 0
overflow = False

for _ in range(num_lines):
    if total_value > 2**32:
        break
    line = input()
    if line == "add":  # add
        loop_value += 1
    elif line[:3] == "for":  # loop
        N = int(line.strip().split()[1])
        loop_stack.append(N)
    else:  # end loop
        loop_value *= loop_stack.pop()

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0

if overflow:
    print("OVERFLOW!!!")
else:
    print(total_value)


from collections import deque

num_lines = int(input())
loop_stack = deque()

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0
        if (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])
        loop_sum *= loop_iters
        if loop_sum > 0:
            if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                loop_stack[0] += loop_sum
            else:
                loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        else:
            loop_stack.appendleft(1)

ans = sum(loop_stack)
print(ans if ans < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
lines = [0] * num_lines

loop_stack = deque()
total_value = 0
loop_value = 0  # sum per iter. of current loop
for _ in range(num_lines):
    line = input()

    if line == "add":
        if len(loop_stack) == 0:
            total_value += 1
        else:
            loop_stack.append("add")
    elif line[:3] == "for":
        loop_num = int(line.strip().split()[1])
        loop_stack.append(loop_num)
    else:
        cmd = loop_stack.pop()
        add_counter = 0
        while cmd == "add":
            add_counter += 1
            cmd = loop_stack.pop()
        loop_value = (loop_value + add_counter) * cmd

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0
print(total_value if total_value < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()
overflow = False
broken = False

for j in range(num_lines):
    line = input()
    if not overflow:
        if line[:3] == "for":
            loop_stack.appendleft(line)
        elif line[:3] == "end":
            # keep going until you pop the start of loop, then push the sum
            k = loop_stack.popleft()
            loop_sum = 0  # integer equivalent of the loop
            if (isinstance(k, int)):
                loop_sum += k
                k = loop_stack.popleft()

            loop_iters = int(k.strip().split()[1])   # the N in [for N]
            loop_sum *= loop_iters
            if loop_sum > 0:
                if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                    loop_stack[0] += loop_sum
                else:
                    loop_stack.appendleft(loop_sum)
        else:  # add
            if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                loop_stack[0] += 1
            else:
                loop_stack.appendleft(1)

    if (len(loop_stack) > 0 and isinstance(loop_stack[0], int) and loop_stack[0] > 2**32):
        overflow = True
        broken = True
        break

if not broken:
    k = sum(loop_stack)
    if k < 2 ** 32:
        print(k)
    else:
        print("OVERFLOW!!!")
else:
    print("OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()
total_sum = 0
overflow = False

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0  # integer equivalent of the loop
        if (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])   # the N in [for N]
        loop_sum *= loop_iters
        if len(loop_stack) == 0:
            total_sum += loop_sum
        else:
            if isinstance(loop_stack[0], int):
                loop_stack[0] += loop_sum
            else:
                loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        elif len(loop_stack) > 0:
            loop_stack.appendleft(1)
        else:
            total_sum += 1
    if total_sum > 2**32 or loop_stack[0] > 2**32:
        overflow = True
        break

ans = total_sum
print(total_sum if not overflow else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())

loop_stack = deque()
total_value = 0
loop_value = 0
overflow = False

for _ in range(num_lines):
    if total_value >= 2**32:
        break
    line = input()
    if line == "add":  # add
        loop_value += 1
    elif line[:3] == "for":  # loop
        N = int(line.strip().split()[1])
        loop_stack.append(N)
    else:  # end loop
        loop_value *= loop_stack.pop()

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0

if overflow:
    print("OVERFLOW!!!")
else:
    print(total_value)


from collections import deque

num_lines = int(input())

loop_stack = deque()
total_value = 0
loop_value = 0
overflow = False

for _ in range(num_lines):
    line = input()
    if line == "add":  # add
        if len(loop_stack) == 0:
            total_value += 1
        else:
            loop_value += 1
    elif line[:3] == "for":  # loop
        N = int(line.strip().split()[1])
        loop_stack.append(N)
    else:  # end loop
        loop_value *= loop_stack.pop()
        if len(loop_stack) == 0:
            total_value += loop_value
            loop_value = 0

    if total_value >= 2**32:
        overflow = True
        break

print("OVERFLOW!!!" if overflow else total_value)


from collections import deque

num_lines = int(input())
lines = [0] * num_lines

loop_stack = deque()
total_value = 0
loop_value = 0  # sum per iter. of current loop
curr_sum = 0
for _ in range(num_lines):
    line = input()
    # todo: replace add append with counter
    if line == "add":
        if len(loop_stack) == 0:
            total_value += 1
        else:
            curr_sum += 1
            # print("added to curr_sum")
    elif line[:3] == "for":
        loop_num = int(line.strip().split()[1])
        loop_stack.appendleft("for " + str(loop_num))
    else:

        if curr_sum != 0:
            loop_stack.appendleft("sum " + str(curr_sum))
            curr_sum = 0
        # print("end of loop")
        # print(loop_stack)
        cmd = loop_stack.popleft()
        sum = 0
        if cmd[:3] == "sum":
            sum = int(cmd.strip().split()[1])
            cmd = loop_stack.popleft()
        if cmd[:3] == "for":
            cmd = int(cmd.strip().split()[1])
        loop_value = (loop_value + sum) * cmd
        # print("loop value updated to {}".format(loop_value))

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0
    # print(loop_stack)
    # print(curr_sum)

print(total_value if total_value < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())

loop_stack = deque()
total_value = 0
loop_value = 0

for _ in range(num_lines):
    line = input()
    if line == "add":  # add
        loop_value += 1
    elif line[:3] == "for":  # loop
        N = int(line.strip().split()[1])
        loop_stack.append(N)
    else:  # end loop
        loop_value *= loop_stack.pop()

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0

print(total_value if total_value < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()
total_sum = 0

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0  # integer equivalent of the loop
        if (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])   # the N in [for N]
        loop_sum *= loop_iters
        if len(loop_stack) == 0:
            total_sum += loop_sum
        else:
            if isinstance(loop_stack[0], int):
                loop_stack[0] += loop_sum
            else:
                loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        elif len(loop_stack) > 0:
            loop_stack.appendleft(1)
        else:
            total_sum += 1
    if total_sum > 2**32 or loop_stack[0] > 2**32:
        break

ans = total_sum
print(ans if ans < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()
overflow = False

for j in range(num_lines):
    line = input()
    if not overflow:
        if line[:3] == "for":
            loop_stack.appendleft(line)
        elif line[:3] == "end":
            # keep going until you pop the start of loop, then push the sum
            k = loop_stack.popleft()
            loop_sum = 0  # integer equivalent of the loop
            if (isinstance(k, int)):
                loop_sum += k
                k = loop_stack.popleft()

            loop_iters = int(k.strip().split()[1])   # the N in [for N]
            loop_sum *= loop_iters
            if loop_sum > 0:
                if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                    loop_stack[0] += loop_sum
                else:
                    loop_stack.appendleft(loop_sum)
        else:  # add
            if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                loop_stack[0] += 1
            else:
                loop_stack.appendleft(1)

    if (len(loop_stack) > 0 and isinstance(loop_stack[0], int) and loop_stack[0] > 2**32):
        overflow = True
        break

k = sum(loop_stack)
overflow = k < 2**32

print("OVERFLOW!!!" if overflow else k)


from collections import deque

num_lines = int(input())

loop_stack = deque()
total_value = 0
loop_value = 0
overflow = False

for _ in range(num_lines):
    line = input()
    if line == "add":  # add
        if len(loop_stack) = 0:
            total_value += 1
        else:
            loop_value += 1
    elif line[:3] == "for":  # loop
        N = int(line.strip().split()[1])
        loop_stack.append(N)
    else:  # end loop
        loop_value *= loop_stack.pop()

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0

    if total_value >= 2**32:
        overflow = True
        break

if overflow:
    print("OVERFLOW!!!")
else:
    print(total_value)


from collections import deque

num_lines = int(input())

loop_stack = deque()
total_value = 0
loop_value = 0
overflow = False

for _ in range(num_lines):
    line = input()
    if line == "add":  # add
        if len(loop_stack) == 0:
            total_value += 1
        else:
            loop_value += 1
    elif line[:3] == "for":  # loop
        N = int(line.strip().split()[1])
        loop_stack.append(N)
    else:  # end loop
        loop_value *= loop_stack.pop()

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0

    if total_value >= 2**32:
        overflow = True
        break

if overflow:
    print("OVERFLOW!!!")
else:
    print(total_value)


from collections import deque

num_lines = int(input())
loop_stack = deque()
overflow = False
broken = False

for j in range(num_lines):
    line = input()
    if not overflow:
        if line[:3] == "for":
            loop_stack.appendleft(line)
        elif line[:3] == "end":
            # keep going until you pop the start of loop, then push the sum
            k = loop_stack.popleft()
            loop_sum = 0  # integer equivalent of the loop
            if (isinstance(k, int)):
                loop_sum += k
                k = loop_stack.popleft()

            loop_iters = int(k.strip().split()[1])   # the N in [for N]
            loop_sum *= loop_iters
            if loop_sum > 0:
                if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                    loop_stack[0] += loop_sum
                else:
                    loop_stack.appendleft(loop_sum)
        else:  # add
            if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                loop_stack[0] += 1
            else:
                loop_stack.appendleft(1)

    if (len(loop_stack) > 0 and isinstance(loop_stack[0], int) and loop_stack[0] > 2**32):
        overflow = True
        broken = True
        break

if not broken:
    k = sum(loop_stack)
    if k > 2 ** 32:
        print("OVERFLOW!!!")
    else:
        print(k)
else:
    print("OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()
total_sum = 0

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0  # integer equivalent of the loop
        if (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])   # the N in [for N]
        loop_sum *= loop_iters
        if loop_sum > 0:
            if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                loop_stack[0] += loop_sum
            elif len(loop_stack) > 0:
                loop_stack.appendleft(loop_sum)
            else:
                total_sum += loop_sum
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        elif len(loop_stack) > 0:
            loop_stack.appendleft(1)
        else:
            total_sum += 1

ans = total_sum
print(ans if ans < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0
        while (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()
        loop_iters = int(k.strip().split()[1])
        loop_sum *= loop_iters
        loop_stack.appendleft(loop_sum)
    else:  # add
        loop_stack.appendleft(1)

ans = sum(loop_stack)
print(ans if ans < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()
total_sum = 0

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0  # integer equivalent of the loop
        if (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])   # the N in [for N]
        loop_sum *= loop_iters
        if len(loop_stack) == 0:
            total_sum += loop_sum
        else:
            if isinstance(loop_stack[0], int):
                loop_stack[0] += loop_sum
            else:
                loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        elif len(loop_stack) > 0:
            loop_stack.appendleft(1)
        else:
            total_sum += 1
    if total_sum > 2**32:
        break

ans = total_sum
print(ans if ans < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())

loop_stack = deque()
total_value = 0
loop_value = 0
overflow = False

for _ in range(num_lines):
    line = input()
    if line == "add":  # add
        if len(loop_stack) == 0:
            total_value += 1
        else:
            loop_stack.append(line)
    elif line[:3] == "for":  # loop
        N = int(line.strip().split()[1])
        loop_stack.append(N)
    else:  # end loop
        # pop until you get start of loop
        # count the adds along the way
        add_count = 0
        cmd = loop_stack.pop()

        while (cmd == "add"):
            add_count += 1
            cmd = loop_stack.pop()
        loop_value = cmd * add_count + loop_value * cmd

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0

    if total_value >= 2**32:
        overflow = True
        break

print("OVERFLOW!!!" if overflow else total_value)


from collections import deque

num_lines = int(input())

loop_stack = deque()
total_value = 0
loop_value = 0
overflow = False

for _ in range(num_lines):
    line = input()
    if line == "add":  # add
        loop_value += 1
    elif line[:3] == "for":  # loop
        N = int(line.strip().split()[1])
        loop_stack.append(N)
    else:  # end loop
        loop_value *= loop_stack.pop()

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0

    if total_value >= 2**32:
        overflow = True
        break

if overflow:
    print("OVERFLOW!!!")
else:
    print(total_value)


from collections import deque

num_lines = int(input())
lines = [0] * num_lines

loop_stack = deque()
total_value = 0
loop_value = 0  # sum per iter. of current loop
curr_sum = 0
for _ in range(num_lines):
    line = input()

    if line == "add":
        if len(loop_stack) == 0:
            total_value += 1
        else:
            curr_sum += 1

    elif line[:3] == "for":
        loop_num = int(line.strip().split()[1])
        loop_stack.append("for " + str(loop_num))
    else:

        if curr_sum != 0:
            loop_stack.append("sum " + str(curr_sum))
            curr_sum = 0
        cmd = loop_stack.pop()
        sum = 0
        if cmd[:3] == "sum":
            sum = int(cmd.strip().split()[1])
            cmd = loop_stack.pop()
        if cmd[:3] == "for":
            cmd = int(cmd.strip().split()[1])
        loop_value = (loop_value + sum) * cmd

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0

print(total_value if total_value < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()
overflow = False

for j in range(num_lines):
    line = input()
    if not overflow:
        if line[:3] == "for":
            loop_stack.appendleft(line)
        elif line[:3] == "end":
            # keep going until you pop the start of loop, then push the sum
            k = loop_stack.popleft()
            loop_sum = 0  # integer equivalent of the loop
            if (isinstance(k, int)):
                loop_sum += k
                k = loop_stack.popleft()

            loop_iters = int(k.strip().split()[1])   # the N in [for N]
            loop_sum *= loop_iters
            if loop_sum > 0:
                if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                    loop_stack[0] += loop_sum
                else:
                    loop_stack.appendleft(loop_sum)
        else:  # add
            if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                loop_stack[0] += 1
            else:
                loop_stack.appendleft(1)

    if (len(loop_stack) > 0 and isinstance(loop_stack[0], int) and loop_stack[0] > 2**32):
        overflow = True
        break

k = sum(loop_stack)
if k > 2 ** 32:
    overflow = True
if overflow:
    print("OVERFLOW!!!")
else:
    print(sum(loop_stack))


from collections import deque

num_lines = int(input())
loop_stack = deque()

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0
        while (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()
        loop_iters = int(k.strip().split()[1])
        loop_sum *= loop_iters
        loop_stack.appendleft(loop_sum)
    else:  # add
        loop_stack.appendleft(1)

ans = sum(loop_stack)
print(ans if ans < 2*32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
lines = [0] * num_lines

loop_stack = deque()
total_value = 0
loop_value = 0  # sum per iter. of current loop
curr_sum = 0
for _ in range(num_lines):
    line = input()
    # todo: replace add append with counter
    if line == "add":
        if len(loop_stack) == 0:
            total_value += 1
        else:
            curr_sum += 1
            # print("added to curr_sum")
    elif line[:3] == "for":
        loop_num = int(line.strip().split()[1])
        loop_stack.appendleft("for " + str(loop_num))
    else:

        if curr_sum != 0:
            loop_stack.appendleft("sum " + str(curr_sum))
            curr_sum = 0
        # print("end of loop")
        # print(loop_stack)
        cmd = loop_stack.popleft()
        sum = 0
        if cmd[:3] == "sum":
            sum = int(cmd.strip().split()[1])
            cmd = loop_stack.popleft()
        if cmd[:3] == "for":
            cmd = int(cmd.strip().split()[1])
        loop_value = (loop_value + sum) * cmd
        # print("loop value updated to {}".format(loop_value))

    if len(loop_stack) == 0:
        total_value += loop_value
        loop_value = 0
    # print(loop_stack)

print(total_value if total_value < 2**32 else "OVERFLOW!!!")


from collections import deque

num_lines = int(input())
loop_stack = deque()
overflow = False

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0  # integer equivalent of the loop
        if (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])   # the N in [for N]
        loop_sum *= loop_iters
        if loop_sum > 0:
            if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
                loop_stack[0] += loop_sum
            else:
                loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        else:
            loop_stack.appendleft(1)

    if (len(loop_stack) > 0 and isinstance(loop_stack[0], int) and loop_stack[0] > 2**32):
        overflow = True
        break

if overflow:
    print("OVERFLOW!!!")
else:
    print(sum(loop_stack))


from collections import deque

num_lines = int(input())
loop_stack = deque()
total_sum = 0
overflow = False

for j in range(num_lines):
    line = input()
    if line[:3] == "for":
        loop_stack.appendleft(line)
    elif line[:3] == "end":
        # keep going until you pop the start of loop, then push the sum
        k = loop_stack.popleft()
        loop_sum = 0  # integer equivalent of the loop
        if (isinstance(k, int)):
            loop_sum += k
            k = loop_stack.popleft()

        loop_iters = int(k.strip().split()[1])   # the N in [for N]
        loop_sum *= loop_iters
        if len(loop_stack) == 0:
            total_sum += loop_sum
        else:
            if isinstance(loop_stack[0], int):
                loop_stack[0] += loop_sum
            else:
                loop_stack.appendleft(loop_sum)
    else:  # add
        if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
            loop_stack[0] += 1
        elif len(loop_stack) > 0:
            loop_stack.appendleft(1)
        else:
            total_sum += 1
    if total_sum > 2**32 or (len(loop_stack) > 0 and isinstance(loop_stack[0], int) and loop_stack[0] > 2**32):
        overflow = True
        break

print(total_sum if not overflow else "OVERFLOW!!!")


def solution():
    num = int(input())
    result = 0
    stack = []

    for i in range(num) :
        str_input = input()
        if str_input == "add" :
            if len(stack) != 0 and "+" in stack[-1] :
                n = int(stack.pop()[1:])
                stack.append("+"+str(n+1))
            else :
                stack.append("+1")
        elif str_input == "end" :
            if "+" in stack[-1] :
                pop1 = int(stack.pop()[1:])
                pop2 = int(stack.pop()[1:])
                stack.append("+"+str(pop1*pop2))
            else :
                stack.pop()
        else :
            stack.append("x"+str_input.split()[1])

        #print(stack)

    for i in range(len(stack)) :
        result += int(stack.pop()[1:])
        if result > 2**32 -1 :
            print("OVERFLOW!!!")
            return;
    print(result)
solution()


def solution():
    num = int(input())
    result = 0
    stack = []

    for i in range(num) :
        str_input = input()
        if str_input == "add" :
            if len(stack) != 0 and "+" in stack[-1] :
                n = int(stack.pop()[1:])
                stack.append("+"+str(n+1))
            else :
                stack.append("+1")
        elif str_input == "end" :
            if "+" in stack[-1] and "x" in stack[-2]:
                pop1 = int(stack.pop()[1:])
                pop2 = int(stack.pop()[1:])
                stack.append("+"+str(pop1*pop2))
                if "+" in stack[-1] and "+" in stack[-2]:
                    pop1 = int(stack.pop()[1:])
                    pop2 = int(stack.pop()[1:])
                    stack.append("+"+str(pop1+pop2))
            else :
                stack.pop()
        else :
            stack.append("x"+str_input.split()[1])

        #print(stack)
        if len(stack) != 0 and int(stack[-1][1:]) > 2**32-1 :
            print("OVERFLOW!!!")
            return;

    #print(stack)

    for i in range(len(stack)) :
        result += int(stack.pop()[1:])
        if result > 2**32 -1 :
            print("OVERFLOW!!!")
            return;
    print(result)
solution()


def solution():
    num = int(input())
    result = 0
    stack = []

    for i in range(num) :
        str_input = input()
        if str_input == "add" :
            if len(stack) != 0 and "+" in stack[-1] :
                n = int(stack.pop()[1:])
                stack.append("+"+str(n+1))
            else :
                stack.append("+1")
        elif str_input == "end" :
            if "+" in stack[-1] :
                pop1 = int(stack.pop()[1:])
                pop2 = int(stack.pop()[1:])
                stack.append("+"+str(pop1*pop2))
            else :
                stack.pop()
        else :
            stack.append("x"+str_input.split()[1])

        #print(stack)
        if int(stack[-1][1:]) > 2**32-1 :
            print("OVERFLOW!!!")
            return;

    for i in range(len(stack)) :
        result += int(stack.pop()[1:])
        if result > 2**32 -1 :
            print("OVERFLOW!!!")
            return;
    print(result)
solution()


def solution():
    num = int(input())
    result = 0
    stack = []

    for i in range(num) :
        str_input = input()
        if str_input == "add" :
            if len(stack) != 0 and "+" in stack[-1] :
                n = int(stack.pop()[1:])
                stack.append("+"+str(n+1))
            else :
                stack.append("+1")
        elif str_input == "end" :
            if "+" in stack[-1] and "x" in stack[-2]:
                pop1 = int(stack.pop()[1:])
                pop2 = int(stack.pop()[1:])
                stack.append("+"+str(pop1*pop2))
                if len(stack)>1 and "+" in stack[-1] and "+" in stack[-2]:
                    pop1 = int(stack.pop()[1:])
                    pop2 = int(stack.pop()[1:])
                    stack.append("+"+str(pop1+pop2))
            else :
                stack.pop()
        else :
            stack.append("x"+str_input.split()[1])

        #print(stack)
        if len(stack) != 0 and int(stack[-1][1:]) > 2**32-1 :
            print("OVERFLOW!!!")
            return;

    #print(stack)

    for i in range(len(stack)) :
        result += int(stack.pop()[1:])
        if result > 2**32 -1 :
            print("OVERFLOW!!!")
            return;
    print(result)
solution()


def solution():
    num = int(input())
    result = 0
    stack = []

    for i in range(num) :
        str_input = input()
        if str_input == "add" :
            if len(stack) != 0 and "+" in stack[-1] :
                n = int(stack.pop()[1:])
                stack.append("+"+str(n+1))
            else :
                stack.append("+1")
        elif str_input == "end" :
            if "+" in stack[-1] and "x" in stack[-2]:
                pop1 = int(stack.pop()[1:])
                pop2 = int(stack.pop()[1:])
                stack.append("+"+str(pop1*pop2))
                if "+" in stack[-1] and "+" in stack[-2]:
                    pop1 = int(stack.pop()[1:])
                    pop2 = int(stack.pop()[1:])
                    stack.append("+"+str(pop1+pop2))
            else :
                stack.pop()
        else :
            stack.append("x"+str_input.split()[1])

        #print(stack)
        if len(stack) != 0 and int(stack[-1][1:]) > 2**32-1 :
            print("OVERFLOW!!!")
            return;

    print(stack)

    for i in range(len(stack)) :
        result += int(stack.pop()[1:])
        if result > 2**32 -1 :
            print("OVERFLOW!!!")
            return;
    print(result)
solution()


def solution():
    num = int(input())
    result = 0
    stack = []

    for i in range(num) :
        str_input = input()
        if str_input == "add" :
            if len(stack) != 0 and "+" in stack[-1] :
                n = int(stack.pop()[1:])
                stack.append("+"+str(n+1))
            else :
                stack.append("+1")
        elif str_input == "end" :
            if "+" in stack[-1] :
                pop1 = int(stack.pop()[1:])
                pop2 = int(stack.pop()[1:])
                stack.append("+"+str(pop1*pop2))
            else :
                stack.pop()
        else :
            stack.append("x"+str_input.split()[1])

        #print(stack)
        if len(stack) != 0 and int(stack[-1][1:]) > 2**32-1 :
            print("OVERFLOW!!!")
            return;

    for i in range(len(stack)) :
        result += int(stack.pop()[1:])
        if result > 2**32 -1 :
            print("OVERFLOW!!!")
            return;
    print(result)
solution()


cnt = (1 << 32) - 1
l = int(input().strip())
ans = 0
array = []
multiply = [1]
for i in range(l):
    line = input().strip()
    if line[0] == 'f':
        multiply.append(min(cnt, multiply[-1]*int(line[3:])))
        array.append(int(line[3:]))
    elif line[0] == 'e':
        multiply.pop()
        array.pop()
    elif line[0] == 'a':
        ans += multiply[-1]
if ans >= cnt:
    print('OVERFLOW!!!')
else:
    print(int(ans))


cnt = 1 << 32 - 1
l = int(input().strip())
ans = 0
array = []
multiply = [1]
for i in range(l):
    line = input().strip()
    if line[0] == 'f':
        multiply.append(min(cnt, multiply[-1]*int(line[3:])))
        array.append(int(line[3:]))
    elif line[0] == 'e':
        multiply.pop()
        array.pop()
    elif line[0] == 'a':
        ans += multiply[-1]
if ans >= cnt:
    print('OVERFLOW!!!')
else:
    print(int(ans))


cnt = 1 << 32 - 1
l = int(input().strip())
ans = 0
array = []
multiply = [1]
for i in range(l):
    line = input().strip()
    if line[0] == 'f':
        multiply.append(min(cnt, multiply[-1]*int(line[3:])))
        array.append(int(line[3:]))
    elif line[0] == 'e':
        multiply.pop()
        array.pop()
    elif line[0] == 'a':
        ans += multiply[-1]
if ans > cnt:
    print('OVERFLOW!!!')
else:
    print(int(ans))


cnt = 1 << 32 - 1
l = int(input().strip())
ans = 0
array = []
multiply = 1
for i in range(l):
    line = input().strip()
    if line[:3] == 'for':
        multiply *= int(line[3:])
        array.append(int(line[3:]))
    elif line == 'end':
        multiply /= array[-1]
        array.pop()
    elif line == 'add':
        ans += multiply
    if ans >= cnt or multiply >= cnt:
        break
if ans >= cnt or multiply >= cnt:
    print('OVERFLOW!!!')
else:
    print(int(ans))


cnt = 1 << 32 - 1
l = int(input().strip())
ans = 1
array = []
multiply = 1
for i in range(l):
    line = input().strip()
    if line[:3] == 'for':
        multiply *= int(line[3:])
        array.append(int(line[3:]))
    elif line == 'end':
        multiply /= array[-1]
        array.pop()
    elif line == 'add':
        ans += multiply
    if ans >= cnt:
        break
if ans >= cnt:
    print('OVERFLOW!!!')
else:
    print(int(ans))


cnt = 1 << 32 - 1
l = int(input().strip())
ans = 0
array = []
multiply = 1
for i in range(l):
    line = input().strip()
    if line[:3] == 'for':
        multiply *= int(line[3:])
        array.append(int(line[3:]))
    elif line == 'end':
        multiply /= array[-1]
        array.pop()
    elif line == 'add':
        ans += multiply
    if ans >= cnt:
        break
if ans >= cnt:
    print('OVERFLOW!!!')
else:
    print(int(ans))


cnt = (1 << 32)
l = int(input().strip())
ans = 0
array = []
multiply = [1]
for i in range(l):
    line = input().strip()
    if line[0] == 'f':
        multiply.append(min(cnt, multiply[-1]*int(line[3:])))
        array.append(int(line[3:]))
    elif line[0] == 'e':
        multiply.pop()
        array.pop()
    elif line[0] == 'a':
        ans += multiply[-1]
if ans >= cnt:
    print('OVERFLOW!!!')
else:
    print(int(ans))


# your code goes here
n  = int(input())
st = [[0, 1, 1]]
limit = 2**32 - 1

for _ in  range(n):
	inst = input().split(" ")
	top = st[-1]
	if len(inst) == 2 and inst[1]!='':
		newTop = [top[0], int(inst[1])*top[1], int(inst[1])]
		st.append(newTop)
	elif inst[0] == 'add':
		st[-1][0] += st[-1][1]
	else:
		temp = st[-1][0]
		st.pop()
		st[-1][0] = temp
	if st[-1][0] > limit:
		print("OVERFLOW!!")
		exit(1)
print(st[-1][0])


# your code goes here
n  = int(input())
st = [[0, 1, 1]]
limit = 2**32 - 1

for _ in  range(n):
	inst = input().split(" ")
	top = st[-1]
	if len(inst) == 2 and inst[1]!='':
		newTop = [top[0], int(inst[1])*top[1], int(inst[1])]
		st.append(newTop)
	elif inst[0] == 'add':
		st[-1][0] += st[-1][1]
	else:
		temp = st[-1][0]
		st.pop()
		st[-1][0] = temp
	if st[-1][0] > limit:
		print("OVERFLOW!!!")
		exit(0)
print(st[-1][0])


n  = int(input())
ans = 0
limit = 2**32 - 1
st2 = [1]
m = 1
for _ in  range(n):
	inst = input()
	if inst == "end":
	    m //= st2.pop()
	elif inst == "add":
	    ans += m
	else:
	    t = int(inst.split(" ")[1])
	    if m > limit:
	        m = limit
	    else:
	        m *= t
	    st2.append(t)
	if ans > limit:
	    ans = "OVERFOLW!!!"
	    break
print(ans)


# your code goes here
n  = int(input())
st = [[0, 1, 1]]
limit = 2**32 - 1

for _ in  range(n):
	inst = input().split(" ")
	top = st[-1]
	if len(inst) == 2 and inst[1]!='':
		newTop = [top[0], int(inst[1])*top[1], int(inst[1])]
		st.append(newTop)
	elif inst[0] == 'add':
		st[-1][0] += st[-1][1]
	else:
		temp = st[-1][0]
		st.pop()
		st[-1][0] = temp
	if st[-1][0] > limit:
		print("OVERFLOW!!")
		exit(0)
print(st[-1][0])


# your code goes here
n  = int(input())
st = [[0, 1, 1]]
limit = 2**32 - 1

for _ in  range(n):
	inst = input().split(" ")
	top = st[-1]
	if len(inst) == 2 and inst[1]!='':
		newTop = [top[0], int(inst[1])*top[1], int(inst[1])]
		st.append(newTop)
	elif inst[0] == 'add':
		st[-1][0] += st[-1][1]
	else:
		temp = st[-1][0]
		st.pop()
		st[-1][0] = temp
	if st[-1][0] > limit:
		print("OVERFLOW!!!")
		exit(1)
print(st[-1][0])


n  = int(input())
ans = 0
limit = 2**32 - 1
st2 = [1]
m = 1
for _ in  range(n):
	inst = input()
	if inst == "end":
	    m //= st2.pop()
	elif inst == "add":
	    ans += m
	    if ans > limit:
	        ans = "OVERFLOW!!!"
	        break
	else:
	    t = int(inst.split(" ")[1])
	    if m > limit:
	        t = 1
	    m *= t
	    st2.append(t)
print(ans)


n  = int(input())
ans = 0
limit = 2**32 - 1
st2 = [1]
m = 1
for _ in  range(n):
	inst = input()
	if inst == "end":
	    m //= st2.pop()
	elif inst == "add":
	    ans += m
	else:
	    t = int(inst.split(" ")[1])
	    m *= t
	    st2.append(t)
	if ans > limit:
	    ans = "OVERFLOW!!!"
	    break
print(ans)


n  = int(input())
ans = 0
limit = 2**32 - 1
st2 = [1]
m = 1
for _ in  range(n):
	inst = input()
	if inst == "end":
	    m //= st2.pop()
	elif inst == "add":
	    ans += m
	    if ans > limit:
	        ans = "OVERFLOW!!!"
	        break
	else:
	    t = int(inst.split(" ")[1])
	    if m > limit*2**10:
	        t = 1
	    m *= t
	    st2.append(t)
print(ans)


n  = int(input())
ans = 0
limit = 2**32 - 1
st2 = [1]
m = 1
for _ in  range(n):
	inst = input()
	if inst == "end":
	    m //= st2.pop()
	elif inst == "add":
	    ans += m
	else:
	    t = int(inst.split(" ")[1])
	    if m > limit:
	        m = limit
	        st2.append(1)
	    else:
	        m *= t
	        st2.append(t)
	if ans > limit:
	    ans = "OVERFLOW!!!"
	    break
print(ans)


n  = int(input())
ans = 0
limit = 2**32 - 1
st2 = [1]
m = 1
for _ in  range(n):
	inst = input()
	if inst == "end":
	    m //= st2.pop()
	elif inst == "add":
	    ans += m
	else:
	    t = int(inst.split(" ")[1])
	    if m > limit:
	        m = limit
	    else:
	        m *= t
	    st2.append(t)
	if ans > limit:
	    ans = "OVERFLOW!!!"
	    break
print(ans)


from sys import stdin

def solve():
    #stdin = open("B. Catch Overflow.txt")
    x = 0
    max_x = 2**32 - 1
    loop = 1

    pre_fors = []

    for _ in range(int(stdin.readline())):
        command = [k for k in stdin.readline().split()]

        if command[0] == "add":
            x += loop
        elif command[0] == "for":
            k = int(command[1])
            loop *= k
            pre_fors.append(k)
        else:
            if pre_fors:
                k = pre_fors.pop()
                loop //= k

    print ("OVERFLOW!!!" if x > max_x else x)

if __name__ == "__main__":
    solve()


from sys import stdin

def solve():
    #stdin = open("B. Catch Overflow.txt")
    x = 0
    max_x = 2**32 - 1
    loop = 1

    pre_fors = []

    for _ in range(int(stdin.readline())):
        command = [k for k in stdin.readline().split()]

        if command[0] == "add":
            x += loop
            if x > max_x:
                break
        elif command[0] == "for":
            k = int(command[1])
            loop *= k
            pre_fors.append(k)
        else:
            if pre_fors:
                k = pre_fors.pop()
                loop //= k
            else:
                x = max_x + 10
                break

    print ("OVERFLOW!!!" if x > max_x else x)

if __name__ == "__main__":
    solve()


from sys import stdin

def solve():
    #stdin = open("B. Catch Overflow.txt")
    x = 0
    max_x = 2**32 - 1
    loop = 1

    pre_fors = []
    mult = []
    flag = 0

    for _ in range(int(stdin.readline())):
        command = [k for k in stdin.readline().split()]

        if command[0] == "add":
            if flag:
                x = max_x + 10
                break
            x += loop
        elif command[0] == "for":
            k = int(command[1])
            if flag or loop*k > max_x:
                mult.append(k)
                flag = 1
            else:
                loop *= k
                pre_fors.append(k)
        else:
            if flag:
                mult.pop()
                if not mult:
                    flag = 0
            else:
                k = pre_fors.pop()
                loop //= k

    print ("OVERFLOW!!!" if x > max_x else x)

if __name__ == "__main__":
    solve()


from collections import defaultdict, deque
from bisect import bisect_left

def solve():
    stdin = open("B. Catch Overflow.txt")

    x = 0
    max_x = 2**32 - 1
    loop = 1

    pre_fors = []

    for _ in range(int(stdin.readline())):
        command = [k for k in stdin.readline().split()]

        if command[0] == "add":
            x += loop
        elif command[0] == "for":
            k = int(command[1])
            loop *= k
            pre_fors.append(k)
        else:
            k = pre_fors.pop()
            loop //= k

    print ("OVERFLOW!!!" if x > max_x else x)

if __name__ == "__main__":
    solve()


from sys import stdin

def solve():
    #stdin = open("B. Catch Overflow.txt")
    x = 0
    max_x = 2**32 - 1
    loop = 1

    pre_fors = []

    for _ in range(int(stdin.readline())):
        command = [k for k in stdin.readline().split()]

        if command[0] == "add":
            x += loop
            if x > max_x:
                break
        elif command[0] == "for":
            k = int(command[1])
            loop *= k
            pre_fors.append(k)
        else:
            if pre_fors:
                k = pre_fors.pop()
                loop //= k

    print ("OVERFLOW!!!" if x > max_x else x)

if __name__ == "__main__":
    solve()


n=int(input())
x=0
a=[1]
k=1
good=0
for i in range(n):
    s=input()
    if x>2**32-1:
        continue
    if 'for' in s:
        m=int(s[4:])
        a.append(m*a[-1])
    elif 'end' in s:
        a.pop()
    else:
        x+=a[-1]
        if x>2**32-1:
            print('OVERFLOW!!!')
            exit(0)
if x>2**32-1:
    print('OVERFLOW!!!')
else:
    print(x)


n=int(input())
x=0
a=[1]
INF=2**32
for i in range(n):
    s=input()
    if x>2**32-1:
        continue
    if 'for' in s:
        m=int(s[4:])
        a.append(min(m*a[-1],INF))
    elif 'end' in s:
        a.pop()
    else:
        x+=a[-1]
        if x>INF-1:
            print('OVERFLOW!!!')
            exit(0)
if x>INF-1:
    print('OVERFLOW!!!')
else:
    print(x)


n=int(input())
x=0
a=[1]
k=1
good=0
for i in range(n):
    s=input()
    if x>2**32-1:
        continue
    if 'for' in s:
        m=int(s[4:])
        a.append(m*a[-1])
    elif 'end' in s:
        a.pop()
    else:
        x+=a[-1]
if x>2**32-1:
    print('OVERFLOW!!!')
else:
    print(x)


k=0
ad=[]
res=0
for _ in range(int(input())):
	s=input()
	if s[:3]=='add':
		if len(ad)>0:
			ad[-1][0]+=1
		else:
			res+=1
	elif s[:3]=='end':
		k=ad[-1][0]*ad[-1][1]
		ad.pop()
		if len(ad)>0:
			ad[-1][0]+=k
		else:
			res+=k
		k=0
	else:
		p=int(s[4:])
		ad.append([0,p])
	# print(ad,res,k)
if res>2**32-1:
	print('OVERFLOW!!!')
else:
	print(res)


l = int(input())
t = 0
f = []
a = []
limit = 1<<32
done = False
for i in range(l):
    s = input().strip()
    if s == "add":
        if len(f) == 0:
            t+=1
        else:
            a[-1] += 1
    elif s =="end":
        fo = f.pop()
        ao = a.pop()
        if ao == 0:
            continue
        elif len(f) > 0:
            a[-1] += fo * ao
            if f[-1] * a[-1] >= limit:
                done = True
                print("OVERFLOW!!!")
        else:
            t += fo * ao
    else:
        f.append(int(s.split()[1]))
        a.append(0)
if t >= limit and not done:
    print("OVERFLOW!!!")
if not done:
    print(t)


l = int(input())
t = 0
f = []
a = []
limit = 1<<32
done = False
for i in range(l):
    s = input().strip()
    if s == "add":
        if len(f) == 0:
            t+=1
        else:
            a[-1] += 1
    elif s =="end":
        fo = f.pop()
        ao = a.pop()
        if ao == 0:
            continue
        elif len(f) > 0:
            a[-1] += fo * ao
            if f[-1] * a[-1] >= limit:
                done = True
                print("OVERFLOW!!!")
                break;
        else:
            t += fo * ao
    else:
        f.append(int(s.split()[1]))
        a.append(0)
if not done:
    if t >= limit:
        print("OVERFLOW!!!")
    else:
        print(t)


l = int(input())
t = 0
limit = 1<<32 -1
f = []
a = []
for i in range(l):
    s = input().strip()
    if s.startswith("for"):
        times = int(s.split()[1])
        f.append(times)
        a.append(0)
    elif s.startswith("add"):
        if len(f) == 0:
            t+=1
        else:
            a[-1] += 1
    else:
        fo = f.pop()
        ao = a.pop()
        if len(f) > 0:
            a[-1] +=  fo * ao
        else:
            t += fo * ao
    # print(s, f,a,t)
if t > limit :
    print("OVERFLOW!!!")
else:
    print(t)


l = int(input())
t = 0
f = []
a = []
limit = 1<<32
done = False
for i in range(l):
    s = input().strip()
    if s == "add":
        if len(f) == 0:
            t+=1
        else:
            a[-1] += 1
    elif s =="end":
        fo = f.pop()
        ao = a.pop()
        if ao == 0:
            continue
        elif len(f) > 0:
            a[-1] += fo * ao
            if f[-1] * a[-1] >= limit:
                done = True
                print("OVERFLOW!!!")
                break;
        else:
            t += fo * ao
    else:
        f.append(int(s.split()[1]))
        a.append(0)
if t >= limit and not done:
    print("OVERFLOW!!!")
if not done:
    print(t)


l = int(input())
t = 0
limit = 1<<32 -1
f = []
a = []
done = False
for i in range(l):
    s = input().strip()
    if s.startswith("for"):
        times = int(s.split()[1])
        f.append(times)
        a.append(0)
    elif s.startswith("add"):
        if len(f) == 0:
            t+=1
        else:
            a[-1] += 1
    else:
        fo = f.pop()
        ao = a.pop()
        if len(f) > 0:
            a[-1] +=  fo * ao
            if f[-1] * a[-1] > limit:
                done = True
                print("OVERFLOW!!!")
        else:
            t += fo * ao
    # print(s, f,a,t)
if t > limit and not done:
    print("OVERFLOW!!!")
if not done:
    print(t)


from math import *
n=int(input())

val=0
l =[1]
mx=2**32

for i in range(0,n,1):
	s=input()
	if s=='end':
		l.pop()
	elif s=='add':
		val=val+l[len(l)-1]
	else:
		x=int(input())
		k=min(x*l[len(l)-1],mx)
		l.append(k)

if val>=mx:
	print("OVERFLOW!!!")
else:
	print(val)


n=int(input())

val=0
l =[1]
mx=2**32

for i in range(0,n,1):
	s=input()
	if s=='end':
		l.pop()
	elif s=='add':
		val=val+l[len(l)-1]
	else:
		x=int(input())
		l.append(x*l[-1])

if val>=mx:
	print("OVERFLOW!!!")
else:
	print(val)


 n=int(input())
  f=[]
  v=[0]
  for _ in range(n):
    s=input()
    if s=='add':
      v[-1]+=1
    elif s=='end':
      x=v.pop()*f.pop()
      v[-1]+=x
    else:
      f+=int(s.split()[1]),
      v+=0,
    if v[-1]>=1<<32:
      print('OVERFLOW!!!')
      return
  print(v[0])


def go():
  n=int(input())
  f=[]
  v=[0]
  for _ in range(n):
    s=input()
    if s=='add':
      v[-1]+=1
    elif s=='end':
      x=v.pop()*f.pop()
      v[-1]+=x
    else:
      f+=int(s.split()[1]),
      v+=0,
    if v[-1]>=1<<32:
      print('OVERFLOW!!!')
      return
  print(v[0])

go()


s=[0]
t=[]
for c in map(input,' '*int(input())):
 if c[0]>'e':s.append(0.0);t.append(int(c[4:]))
 else:s[-1]=s[-1]+1 if c[0]<'b'else s.pop()*t.pop()+s[-1]
print(int(s[0])if s[0]<2**32 else'OVERFLOW!!!')


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#define MAX (1<<30)
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define ab(x) ((x)>0?(x):(-(x)))
#define ALL(x) (x).begin(),(x).end()
#define X first
#define Y second
using namespace std;
double s[51][51];
int E[51][51];
bool v[51];
double dp[51];
int n, m, x;
vector<double> a;
bool flag = false;
int parent[51];
void pro(int f,double val){
	if (parent[f] == 0) return;
	s[parent[f]][f] -= val;
	s[f][parent[f]] += val;
	pro(parent[f],val);
}
double go(int f){
	if (v[f]) return dp[f];
	if (f == 1) return 1e18;
	v[f] = true;
	for (int i = 1; i <= n; i++) if(s[i][f] != 0 && min(go(i),s[i][f]) > dp[f]){
		dp[f] = min(go(i), s[i][f]);
		parent[f] = i;
	}
	return dp[f];
}
int find_flow(double how){
	int ret = 0;
	for (int i = 0;; i++){
		flag = false;
		for (int j = 1; j <= n; j++) v[j] = dp[j] = parent[j] =  0;
		double now = go(n);
		if (now < how) return ret;
		ret += (int) (now / how);
		pro(n,((int)now/how)*how);
		a.push_back((double) now);
	}
	return ret;
}
int main(){
	scanf("%d %d %d", &n, &m, &x);
	for (int i = 0; i < m; i++){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		E[a][b] = c;
	}
	double top = 1000000, bot = 0, ans = 0;
	while (1){
		double mid = (top + bot) / 2;
		for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) s[i][j] = E[i][j];
		int cnt = find_flow(mid);
		if (cnt>=x){
			ans = mid;
			bot = mid;
		}
		else top = mid;
		if (top - bot < 0.00000000000005L) break;
	}
	printf("%.10lf\n", (ans+0.000000001)*x);
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#define MAX (1<<30)
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define ab(x) ((x)>0?(x):(-(x)))
#define ALL(x) (x).begin(),(x).end()
#define X first
#define Y second
using namespace std;
double s[51][51];
ll E[51][51];
bool v[51];
double dp[51][51];
int n, m, x;
int parent[51][51];
void pro(int st,int ed,double val){
	if(parent[st][ed] == 0){
		s[st][ed] -= val;
		s[ed][st] += val;
		return;
	}
	pro(st,parent[st][ed],val);
	pro(parent[st][ed],ed,val);
	return;
}
double go(){
	for(int i=1; i<=n; i++) for(int j=1; j<=n; j++){
		if(i == j) dp[i][j] = 1e18;
		else dp[i][j] = s[i][j];
	}
	for(int k=1; k<=n; k++)
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++){
				if(dp[i][k] != 0 && dp[k][j] != 0 && dp[i][j] < min(dp[i][k],dp[k][j])){
					dp[i][j] = min(dp[i][k],dp[k][j]);
					parent[i][j] = k;
				}
			}
	return dp[1][n];
}
int find_flow(double how){
	int ret = 0;
	for (int i = 0;; i++){
		for (int j = 1; j <= n; j++) v[j] = 0;
		memset(dp,0,sizeof(dp));
		memset(parent,0,sizeof(parent));
		double now = go();
		if (now < how) return ret;
		int tmp = (int) (now / how);
		ret += tmp;
		pro(1,n,tmp*how);
	}
	return ret;
}
int main(){
	scanf("%d %d %d", &n, &m, &x);
	for (int i = 0; i < m; i++){
		int a, b;
		ll c;
		scanf("%d %d %I64d", &a, &b, &c);
		E[a][b] = c*10000L;
	}
	double top = 1000000000000000.0L, bot = 0, ans = 0;
	while (1){
		double mid = (top + bot) / 2;
		double c = (mid/x);
		for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) s[i][j] = E[i][j];
		int cnt = find_flow(c);
		if (cnt>=x){
			ans = mid;
			bot = mid;
		}
		else top = mid;
		if (top - bot < 0.001L) break;
	}
	printf("%.10lf\n", ans/10000);
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#define MAX (1<<30)
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define ab(x) ((x)>0?(x):(-(x)))
#define ALL(x) (x).begin(),(x).end()
#define X first
#define Y second
using namespace std;
double s[51][51];
ll E[51][51];
bool v[51];
double dp[51][51];
int n, m, x;
vector<double> a;
bool flag = false;
int parent[51][51];
void pro(int st,int ed,double val){
	if(parent[st][ed] == 0){
		s[st][ed] -= val;
		s[ed][st] += val;
		return;
	}
	pro(st,parent[st][ed],val);
	pro(parent[st][ed],ed,val);
	return;
}
double go(){
	for(int i=1; i<=n; i++) for(int j=1; j<=n; j++){
		if(i == j) dp[i][j] = 1e18;
		else dp[i][j] = s[i][j];
	}
	for(int k=1; k<=n; k++)
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++){
				if(dp[i][k] != 0 && dp[k][j] != 0 && dp[i][j] < min(dp[i][k],dp[k][j])){
					dp[i][j] = min(dp[i][k],dp[k][j]);
					parent[i][j] = k;
				}
			}
	return dp[1][n];
}
int find_flow(double how){
	int ret = 0;
	for (int i = 0;; i++){
		flag = false;
		for (int j = 1; j <= n; j++) v[j] = 0;
		memset(dp,0,sizeof(dp));
		memset(parent,0,sizeof(parent));
		double now = go();
		if (now < how) return ret;
		int tmp = (int) (now / how + 0.000001L);
		ret += tmp;
		pro(1,n,tmp*how);
		a.push_back((double) now);
	}
	return ret;
}
int main(){
	scanf("%d %d %d", &n, &m, &x);
	for (int i = 0; i < m; i++){
		int a, b;
		ll c;
		scanf("%d %d %I64d", &a, &b, &c);
		E[a][b] = c*10000L;
	}
	double top = 1000000000000000.0L, bot = 0, ans = 0;
	while (1){
		double mid = (top + bot) / 2;
		double c = (mid/x);
		for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) s[i][j] = E[i][j];
		int cnt = find_flow(c);
		if (cnt>=x){
			ans = mid;
			bot = mid;
		}
		else top = mid;
		if (top - bot < 0.001L) break;
	}
	printf("%.10lf\n", ans/10000);
	return 0;
}